1) I have a Wordpress multisite subdomain installation with about 100 sites in the network.
Network Admin - Sites (All Sites) shows them like this:
main site: "www.domain-name.com"
all other sites: "subdomain-name.domain-name.com"
there is also a domain mapping plugin, so they all get access as separate urls:
domain-name1.com
domain-name2.com
...
domain-name100.com
2) Currently urls on all blogs are set to:
domain-name.com/2012/10/26/post-name
domain-name.com/category/category-name
(I used today's date as an example)
This is also the way domains show in Google and Bing search results
3) I am going to remove "2012/10/26/" and "category/" from the urls, so they are gonna look like this:
domain-name.com/post-name
domain-name.com/category-name
...and I need to have a rewrite rule that takes care of redirecting people coming from serps to these new urls
4) I have something like this right now:
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://domain.com/$4 [L,R=301]
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)$ http://domain.com/$4 [L,R=301]
but I am not sure if it is correct / if it is gonna work right, and also I need to have a rule for all 100 websites, and not just one. These versions (only one of them was meant to be used) dont include the "category/" part either.
5) If somebody would have an idea how to do that it would be great (one or two rewrite rules for all sites would be probably best).
Thank you in advance for any info.
You can simplify your regex for the RewriteRule using \d to match digits and only using a match group on the post-name. If this behavior is the same for all of the domains, you can just omit the domain from your RewriteCond and RewriteRule:
RewriteRule ^\d{4}/\d{2}/\d{2}/(.*)$ $1 [L,R=301]
RewriteRule ^category/(.*)$ $1 [L,R=301]
You can test the above rules and resulting URLs with http://htaccess.madewithlove.be/
Related
I have a client whose website develops & sells retirement villages in multiple locations, it's a Wordpress Multisite, with the main site being generic and the subsites are all the different locations. Basically we want to have an abbreviated domain for each location for advertising purposes that takes visitors to the correct location subsite, without changing the url, because we don't want to have to purchase SSL for every single domain/subsite.
so basically
locationA.com
when entered in the address bar goes to
https://mainsite.com/locationA
without changing the subsite url in the browser to LocationA.com - I know how to change the subsite domain via the wordpress admin settings but we don't want to change permalinks/urls unless there is absolutely no other way.
All the domains are parked at the mainsite's hosting,
I've tried redirecting via the cPanel Alias settings going to https://mainsite.com/locationA, but it always just takes us to https://mainsite.com/
RewriteCond %{HTTP_HOST} ^locationA\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.locationA\.com$
RewriteRule ^/?$ "https\:\/\/mainsite\.com\/locationA\/" [R=301,L]
I've tried other various .htaccess edits from other forums but they either break the site or just do the same thing as above and takes us to the generic mainsite.
e.g.
RewriteBase /
RewriteCond %{HTTP_HOST} ^locationA\.com$ [NC]
RewriteRule ^(.*)$ https://mainsite.com/locationA/ [L]
I don't really know what I'm doing with these, just trying things until something works.
Any help or insight would be greatly appreciated, thanks!
Nevermind, fixed it myself. The problem was that I added the domains as an 'Alias', redirection via CPanel worked when I added them as 'Addon Domains' instead.
I have a wordpress site that was hacked and hundreds of urls were created that no longer exist after I cleaned the site up. I have noticed a lot of these urls contains a specific keyword as displayed below
http://www.capecrossfit.com/kamagra-holland/ - I need to rewrite all urls containing the word kamagra to http://www.capecrossfit.com/ - I have tried all the recommendations on near similar requests on this site with no joy, can anyone please advise how this can be done with htaccess?
Pace this rule as very first rule (just below RewriteEngine On line):
RewriteEngine On
RewriteCond %{THE_REQUEST} /kamagra-holland|buy-kamagra-europe|kamagra-super-jelly [NC]
RewriteRule ^ / [L,R=301]
I am trying to create a permanent htaccess redirect (301) from all my domain extensions into the appropriate subdirectories. The "rules" are as follow:
Redirect belgian website to its subdirectory on the main website:
from: www.example.be
to: www.example.com/befr/
Of course I would like to preserve the url parameters (if any) of the "from". Globaly, if someone entered the first url it should redirect to the second url (langage subdirectory in the main website).
I'm using wordpress and I'm hosting on a plesk I've read many things here but I'm stuck, thank you very much in advance for your help
PS: I've tried that but it doesn't work
RewriteCond %{HTTP_HOST} ^(www\.)?example.be$ [NC]
RewriteRule ^(.*) http://www.example.com/befr/$1 [L,R]
After reading your question, your code should be working (with informations you gave).
If it's not, here are some points to check:
1. Make sure mod_rewrite is enabled and htaccess can be executed (Apache config).
2. Your htaccess has to be in root folder (where example.be is forwarded).
3. About your htaccess' code:
since you're using Wordpress, make sure your rule is on top of other rules
don't forget to escape . (second one) in RewriteCond (otherwise it doesn't mean the same) even if it works that way
replace R flag (302 by default) by R=301 if you want a 301 redirect
Your code now looks like this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example\.be$ [NC]
RewriteRule ^(.*)$ http://www.example.com/befr/$1 [R=301,L]
# your other rules (and Wordpress' default rule) here
I have a situation I've not come across before that calls for some interesting mod_rewrite rules and I cant find any examples of someone trying to achieve the same thing in a similar configuration.
Currently I have two domain names which are configured to share the same document root, in said document root is a dynamic php application which, based on the incoming hostname, displays content specific to the that domain.
The domains for example purposes are:
www.example1.com
and
www.example2.co.uk
(one being a TLD the other not)
In addition to this application there are two wordpress installations one for each of the two domain names. As we are not using wordpress MU here I need some fancy rewrites to firstly hide the wordrpess folder, and secondly present the request to the correct folders based on the HTTP_HOST.
Currently I have the following:
RewriteRule ^wp-content(.*) wordpress/example1$1 [L]
RewriteRule ^wp-admin(.*) wordpress/example1/wp-admin$1 [L]
RewriteRule ^wp-login.php$ wordpress/example1/wp-login.php [L,R=301]
And similar rules for content specific pages.
This works well for the single wordpress installation, but obviously not for the second, what I was hoping to do here was something like the following:
RewriteRule ^wp-admin(.*) wordpress/${HTTP_HOST}/wp-admin$1 [L]
However I need to remove the www. and .com from the ${HTTP_HOST} variable (or the www. and .co.uk )
Any suggestions on a way to achieve this or a better approach would be appreciated.
You can use RewriteCond to check for a pattern in HTTP_HOST and then capture part of that pattern.
For instance:
RewriteCond %{HTTP_HOST} ^(?:www\.)?([a-zA-Z0-9_-]+)\.(?:com|co\.uk)$
RewriteRule ^wp-admin(.*) wordpress/%1/wp-admin$1 [L]
The RewriteCond directive above checks to see whether HTTP_HOST fits a domain pattern ending ".com" or ".co.uk" and optionally beginning with "www.". If it does, it captures the interesting part of the domain name.
Then the RewriteRule (which only fires if the RewriteCond does match) is able to refer to the captured part of the RewriteCond pattern by using the %1 back-reference.
The pattern I've used in the RewriteCond above might not suit your needs perfectly, but once you know you can use a back-reference to a pattern captured by RewriteCond, it should be easy for you to use this to get the effect you need.
I recently changed our URL structure for several different pages but I'm having some trouble with the HTACCESS rewrites. I've included the examples below and I'm hoping that someone can help me with the correct rule to use!
http://www.tintworld.com/ny/albany-022/home-window-tinting/ <-- Original URL
http://www.tintworld.com/albany-ny-022/home-window-tinting/ <-- New URL ('ny' is moved)
I'm currently trying to use the following rule but it's not redirecting the original URLs...
RewriteCond %{HTTP_HOST} ^www\.tintworld\.com$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^ny/albany-022/$ http://www.tintworld.com/albany-ny-022? [R=301,NE,NC,L]
Please help. :-)
The problem is likely due matching ^ny/albany-022/$ in your RewriteRule. The $ in regular expressions denotes the end of the line. Try removing the $, and adding the remaining part onto the rewritten URL
RewriteRule ^ny/albany-022/(.*) http://www.tintworld.com/albany-ny-022/$1
The $1 here puts in the part that's matched by the (.*).
if you have several different pages, I would recommend using a plugin like
http://www.weberz.com/plugins/404-redirected/
to keep track of 404 pages and redirect them