I'm trying to remove the www. for a single directory called dir (for example). I need to be able to do this from the .htaccess file in that directory. (I don't have root access.) Any idea how to make this work?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com/dir$ [NC]
RewriteRule ^(.*)$ http://example.com/dir$1 [R=301,L]
Update—the solution:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/dir/$1 [R=301,L]
The HTTP_HOST will not contain the path being accessed you need to match that in the rewrite rule itself:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^dir\/(.*)$ http://example.com/dir/$1 [R=301,L]
Related
I have a website, www.thesite.com and an alias www.lesite.com
i need a htaccess redirection:
I would like that, when I go to www.thesite.com/fr, it redirects me to www.lesite.com/fr
Likewise, when I go to www.lesite.com/en, I would like it to redirect me to www.thesite.com/en
I have tried different methods but i only succeed to create infinite loops !----
Options +FollowSymlinks
RewriteRule ^fr$ http://dev.mariage.ch/fr/ [L]
RewriteRule ^de$ http://dev.hortzeit.ch/de/ [L]
OR
RewriteCond %{HTTP_HOST} !^dev\.hortzeit\.ch\/de\/
RewriteRule (.*) http://dev.hortzeit.ch/de$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^dev\.mariage\.ch\/fr\/
RewriteRule (.*) http://dev.mariage.ch/fr$1 [R=301,L]
You can't use path as part of RewriteCond for HTTP_HOST
instead of dev.hortzeit.ch/de you must use just host part dev.hortzeit.ch
RewriteEngine On
RewriteCond %{HTTP_HOST} !^dev\.hortzeit\.ch [NC]
RewriteRule ^de(/?.*)$ http://dev.hortzeit.ch/de$1 [R=301,NC,L]
RewriteCond %{HTTP_HOST} !^dev\.mariage\.ch [NC]
RewriteRule ^fr(/?.*)$ http://dev.mariage.ch/fr$1 [R=301,NC,L]
I have two domain names for the same website, and need to do a correct rewrite, so that whenever someone accesses the first domain name and all subdirectories, with, or without www. they get redirected to the second domain and subdirectories without www.
I managed to set the redirect for the domain name without subdirectories, but for whatever reason, subdirectories are not getting rewritten.
So when I go to domainnamenumberone.com, or www.domainnamenumberone.com, i get redirected to domaintwo.com – however, when I go to domainnamenumberone.com/wordpress/path or www.domainnamenumberone.com/wordpress/path I remain there, and nothing gets rewritten.
Here's what I placed in .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domainnumberone\.com [NC]
RewriteRule ^(.*)$ http://domaintwo.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^domainnumberone\.com [NC]
RewriteRule ^(.*)$ http://domaintwo.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.domaintwo\.com [NC]
RewriteRule ^(.*)$ http://domaintwo.com/$1 [L,R=301]
Would be grateful for your help!
You need to place this rule as very first rule in DocumentRoot/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domaintwo\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(?:www\.)?domainnumberone\.com [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(\S*)\s [NC]
RewriteRule ^ http://domaintwo.com/%1 [L,R=302,NE]
Then add this line in each child .htaccess like wordpress/ or wordpress/path/ (wherever .htaccess already exists) below RewriteEngine On line
RewriteOptions Inherit
You can use that:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTP_HOST} ^domainnumberone\.com [NC]
RewriteRule ^(.*)$ http://domaintwo.com/$1 [L,R=301]
But it seems to me that it should also work with yours.....
try a different browser (cache problem)
What I am trying to do is to redirect the user who use for example en.domain.com/blog
to domain.com/blog I have three languages en/es/fr
I tried something like this For the english but its not working.
RewriteCond %{HTTP_HOST} ^en\.domain\.com\/blog
RewriteRule ^(.*)$ /blog/$1 [L]
Anyhelp
Thanks
Put this code in your htaccess (which has to be in root folder)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(en|es|fr)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/blog [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
Put this into your document root folder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^en\.domain\.com$
RewriteRule ^blog(.*)$ /blog$1 [R,L]
The HTTP_HOST does not contain any URI (path part). Also you have to switch the "rewrite engine" on.
I have .htaccess files on every subfolder in demo.mydomain.net to redirect to mydomain.net without redirecting image/js files.
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/load
RewriteRule ^/?$ "http\:\/\/mydomain\.net" [R=301,L]
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/load/images
RewriteRule ^/?$ "http\:\/\/mydomain\.net" [R=301,L]
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/load/scripts
RewriteRule ^/?$ "http\:\/\/mydomain\.net" [R=301,L]
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/load/styles
RewriteRule ^/?$ "http\:\/\/mydomain\.net" [R=301,L]
Is there any way I can combine these to a single working file and save it to where my index file is?
You would need the following combined rule within the .htaccess in your directory mapped to demo.mydomain.net
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/load(/(images|scripts|styles))? [NC]
RewriteRule ^ http://mydomain.net [R=301,L]
The above %{REQUEST_URI} regex intercepts all four URL paths.
i would like to redirect 3 different urls, all in one htaccess file. But at the moment it isn't working and only the first rule is always triggered.
I would like to redirect the following:
service.abc.info to www.abc.de
service.abc.info/feedback/abc/ to feedback.abc.info/abc/
service.abc.info/feedback/def/ to feedback.abc.info/def/
For 2. and 3. I also need to redirect the complete Request URI.
Here is my .htaccess file:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^service\.abc\.info$ [NC]
RewriteRule .* http://www.abc.de [R=301,L]
RewriteCond %{HTTP_HOST} ^service\.abc\.info/feedback/abc/$ [NC]
RewriteRule .* http://feedback.abc.info/abc/{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^service\.abc\.info/feedback/def/$ [NC]
RewriteRule .* http://feedback.abc.info/def/{REQUEST_URI} [R=301,L]
The %{HTTP_HOST} variable holds the contents of the Host: request header, which just contains a hostname. No URI paths. You'll need to match the paths in the pattern of the rewrite rule, additionally, since the first rule is a superset of the other two, you need to move that to the end.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^service\.abc\.info$ [NC]
RewriteRule ^/?feedback/abc/(.*)$ http://feedback.abc.info/abc/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^service\.abc\.info$ [NC]
RewriteRule ^/?feedback/def/(.*)$ http://feedback.abc.info/def/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^service\.abc\.info$ [NC]
RewriteRule ^(.*)$ http://www.abc.de/$1 [R=301,L]