I have a site that can be accessed via 3 domains (domain.com, domain.ch, domain.fr). The three use exactly the same files and folder, though.
Regarding the .fr domain (and only this domain), I need the following:
redirect domain.fr (root) to domain.com/fr/france.
This has been achieved with the following rule:
RewriteCond %{HTTP_HOST} ^www\.domain\.fr$
RewriteRule ^/?$ "http\:\/\/www\.domain\.com\/fr\/france" [R=301,L]
It works. (There's also a functioning rule to force www. in front of every URL.)
What I can't get to work is:
redirect domain.fr/fr also to domain.com/fr/france.
and finally, redirect any URL domain.fr/fr/* to domain.com/fr/*
(keeping whatever * stands for).
The trick (to me) is that the same .htaccess file will also be present on domain.com and domain.ch, but those rules must not activate for those domains.
You can put these rules in your htaccess
# Redirect [www.]domain.fr and [www.]domain.fr/fr to www.domain.com/fr/france
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.fr$ [NC]
RewriteRule ^(|fr)$ http://www.domain.com/fr/france [R=301,L]
# Redirect domain.fr/fr/* to domain.com/fr/*
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.fr$ [NC]
RewriteRule ^fr/(.*)$ http://www.domain.com/fr/$1 [R=301,L]
Try :
RewriteCond %{HTTP_HOST} ^www\.domain\.fr$
RewriteCond %{REQUEST_URI} !^/fr/france
RewriteRule ^fr/(.*)$ http://www.domain.com/fr/france/$1 [R=301,L]
Related
I need to redirect a.com/a.html to b.com/a.html htaccess Apache. I have several subdomains that are not being redirected to the b.com(which is fine). and the example below is only the first domain that needs to be redirected. Three other domains are needed to be redirected to b.com as well with all of their subpages as a.com/a.html to b.com/a.html. Any hints?
RewriteCond %{HTTP_HOST} ^(www\.)?nexus21\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^tvlift\.com$ [NC]
RewriteRule ^ http://www.tvlift.com%{REQUEST_URI} [L,NE,R=301]
I would do each subdomain redirect separately. That way it is cleaner and more maintainable. If you are redirecting few known files then name them directly.
RewriteEngine on
RewriteRule "^/foo\.html$" "bar.html" [R]
If there are lots of file or you will be adding in future then use a pattern
RewriteEngine on
RewriteRule "^/docs/(.+)" "http://new.example.com/docs/$1" [R,L]
See this page
http://httpd.apache.org
I have successfully forwarded www.atlantalawvideo.legalvideoconsulting.com to www.atlantalawvideo.com for SEO purposes.
I'm using this code in my .htaccess file in my /atlantalawvideo/ folder:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.atlantalawvideo.com
RewriteRule (.*) http://www.atlantalawvideo.com/$1 [R=301,L]
I'm having trouble forwarding www.legalvideographer-org.legalvideoconsulting.com to www.legalvideographer.org
I'm using this code in my .htaccess file in my /legalvideographer-org/ folder:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.legalvideographer.org
RewriteRule (.*) http://www.legalvideographer.org/$1 [R=301,L]
Not sure what the problem is http://www.legalvideographer-org.legalvideoconsulting.com forward goes nowhere.
The second rewrite is not working because you are not meeting the condition of the %{HTTP_HOST}. You're not using the full host name to check. legalvideographer.org appears to be a subdomain oflegalvideoconsulting.com. See if this works for you.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.legalvideographer-org\.legalvideoconsulting\.com [NC]
RewriteRule (.*) http://www.legalvideographer.org/$1 [R=301,L]
That should work if that is your domain name.
You should also be able to do a simple redirect instead of the rewrite rule
redirct 301 / http://www.legalvideographer.org
I have many pages with the following type of paths and subdomains:
place1.maindomain.com/travel/place1/go/
place2.maindomain.com/travel/place2/go/
place1.maindomain.com/travel/place1/widgets/
place2.maindomain.com/travel/place2/widgets/
I want to make all of these domains redirect automatically with a wildcard to the www and not the subdomain, so they would appear as follows:
www.maindomain.com/travel/place1/go/
www.maindomain.com/travel/place2/go/
www.maindomain.com/travel/place1/widgets/
www.maindomain.com/travel/place2/widgets/
My programmer has tried but he says he cannot do it. Is there a reason this type of subdomain wildcard redirect is not possible?
The redirect is easy. What's preventing you from just doing something like:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?maindomain\.com$ [NC]
RewriteRule ^ http://www.maindomain.com%{REQUEST_URI} [L,R=301]
If you mean tha tthe "place1" part must match the "place1" part in the path, then you can do:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?maindomain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/[^/]+/([^/]+)/
RewriteCond %{HTTP_HOST}|%1 ^([^.]+)\.maindomain\.com|\1$
RewriteRule ^ http://www.maindomain.com%{REQUEST_URI} [L,R=301]
This is the code in my .htaccess file which is in the root directory of my shared hosting.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9\-]+)?$ interest.php?interest=$1 [QSA,L]
RewriteRule ^([a-zA-Z0-9\_\-]+)?/$ interest.php?interest=$1 [QSA,L]
The problem is, In the same directory lies folders of my add on domains. When I am trying to access them, the 2nd line is creating problem and redirecting it to my primary domain. I want the .htaccess to effect only root folder and not its sub folders. I tried reading other similar questions here and tried changing my htaccess accordingly but the problem remained unresolved.
For example.
its redirecting
mysubdomain.mydomain.com
to
www.mydomain.com/mysubdomainfolder
Have your first rule like this:
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Then clear your browser cache and restart your browser.
Well, .htaccess files are designed to apply recursively.
You could try putting a .htaccess in each of the subfolders that correspond to your add on domains with RewriteEngine Off if you want no redirects, or an alternate rewrite rule if you need them.
In addition you may want to add another rewrite condition for the rule, say your add on domain is blah.com you could add
RewriteCond %{HTTP_HOST} !^(.*.)?blah.com
Edit: I should add the new rewrite condition should go below RewriteCond %{HTTP_HOST} !^www.
Edit2: Okay so subdomains then. In which case you basically need to add a Rewrite condition specifying not to apply the rewrite rule if it's a known subdomain. For example:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^(subdomain1|subdomain2|subdomain3)\.domain\.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Now subdomain1.domain.com won't redirect (or subdomain2/3), www.domain.com won't redirect, but anything else will.
I have a URL
http://test.devsite-1.com/test/tbox/
which I want to redirect to
http://tbox.devsite-1.com/
Rule:
RewriteCond %{HTTP_HOST} !^tbox\.(.*)$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.|)(.*)$ [NC]
RewriteCond %{REQUEST_URI} ^/tbox(/.*|)$
RewriteRule /tbox/(.*) http://tbox.%{HTTP_HOST}/$1 [R=301,L]
I don't understand why it is not redirecting me to the URL? Please note I need a generalized rule so that if I change test.devsite-1.com to tempo.devsite-1.com the same should work with the other URL as well.
Try this rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.(.+)$ [NC]
RewriteRule ^test/tbox/(.*)$ http://tbox.%1/$1 [R=301,L]
This will redirect (301 Permanent Redirect)
http://test.devsite-1.com/test/tbox/something-optional
to
http://tbox.devsite-1.com/something-optional
It has to be placed in .htaccess file in website root folder (e.g. http://test.devsite-1.com/.htaccess). If placed elsewhere some tweaking may be required.
It will only work if request is coming via test. subdomain.
And it will only work if URL requested starts with test/tbox/.
All of the above matches your URL examples.