I've set up redirects in a .htaccess file as follows:
RewriteCond %{HTTP_HOST} ^windward\.net$ [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/author/bassemm/$ https://www.windwardstudios.com/team [L,R=301]`
However, when I go to URL http://www.windward.net/author/bassemm/ I'm not redirected to https://www.windwardstudios.com/team. Is there an issue with the way I set up the redirect in the .htaccess file?
Thanks
RewriteRule directive uses a relative URI path as its old path argument. You are using an absolute path /author/bassemm/ that is why your rule didn't work. You need to use a relative URI path starting without / .
RewriteRule ^author/bassemm/$ https://www.windwardstudios.com/team [L,R=301]
and change your RewriteCond
RewriteCond %{HTTP_HOST} ^windward\.net$ [NC]
to
RewriteCond %{HTTP_HOST} ^(www\.)?windward\.net$ [NC]
To redirect both www and non www versions of your domain.
Related
I want to redirect all the urls of a directory (example.com/blog/urlnames) on one domain to a sub-domain (blog.example.com/urlnames)
I tried:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^/blog$ [NC]
RewriteRule (.*) https://blog.example.com/$1 [R=301,L]
I keep getting a 404 error when I type the url on example.com:
https://example.com/blog/5-names-for-actors/
I want this to go to:
https://blog.example.com/5-names-for-actors/
You can use this rule in blog/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule (.*) https://blog.example.com/$1 [R=301,L,NE]
File blog/.htaccess may not be existing already so you may have to create it.
How I can redirect using .htaccess file from domain: testÓwka.net to domain testOwka.net with saving URL path?
For example, when user visit website: testówka.net/login, I want to redirect this user to: testowka.net/login.
I tried in that way:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^testówka\.net$ [NC]
RewriteRule ^ http://ofertowka.net%{REQUEST_URI} [L,R]
and in that way:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^xn\-\-testwka\-o0a\.net$ [NC]
RewriteRule ^ http://testowka.net%{REQUEST_URI} [L,R]
I tried with escape and without but nothing work fine. How I can do it?
Try modify your rewrite to:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?xn--testwka-o0a\.net [NC]
RewriteRule (.*) http://testowka.net/$1 [R=301,L]
I have been at this for a number of hours and cannot get this to work. I have other redirects in this .htaccess file that do work.
I need to redirect as follows.
mydomain.com/dir/subdir/myfile.php to myotherdomain.com/dir/my_index.php
Note that mydomain.com and myotherdomain.com both point to the same root directory.
Here's my code.
RewriteCond %{HTTP_HOST} ^(www.)?postle.com$
RewriteCond %{REQUEST_URI} !^/pi_www/hardface/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /pi_www/hardface/$1
RewriteCond %{HTTP_HOST} ^(www.)?hardfacetechnologies.com$
RewriteRule ^(/)?$ postle_hft/index_hft.php [L]
I have tired all the permutation of this I can think of and nothing works. I really would appreciate some help.
You can use this rule in /dir/subdir/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^myfile\.php$ http://myotherdomain.com/dir/my_index.php [R=302,NC,L]
If you want to avoid external redirect then:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^myfile\.php$ /dir/my_index.php [NC,L]
should also work as both domains point to same site root.
In the .htaccess file in your document root, try:
RewriteCond %{HTTP_HOST} =mydomain.com
RewriteRule ^dir/subdir/myfile\.php$ http://myotherdomain.com/dir/my_index.php [R=302,L]
The order of directives is important. This should come after your canonical www redirect, but before any internal rewrites, and before any redirects that might conflict.
This also assumes that your canonical URL is the bare domain (ie. not the www subdomain) - like with the example in your question. To match the bare domain or the www subdomain (and make it case-insensitive) then change the RewriteCond directive to:
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain.com$ [NC]
Change the temporary (302) redirect to permanent (301) when you are sure it's working OK. (301 redirects are cached by the browser, so makes testing troublesome.)
I have the following code to force WWW in url
rewriteCond %{HTTP_HOST} !^www.example.com [NC]
rewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I want to add a subdomain max.example and refer to www.example.com/update/max directory
If I do not add any rule, max.example.com will redirect to www.example.com/update/max . If I remove force WWW in url it works. But I still need force WWW in url. How to write the rule?
Thanks!
Change your rule to this:
RewriteCond %{HTTP_HOST} !^(www|max)\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]
I'm trying to accomplish the following:
http:// www.example.com/site/abc with a http 301 redirect to subdomain http:// abc.example.com
and back again within Apache:
http:// abc.example.com --> /site/abc
I want both redirects to be defined in the .htaccess in the root folder.
I've tried several combinations, but unfortunately without any luck. This is what I have now:
# 1. redirect uris which start with www. to the domain without www.
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com$
RewriteRule ^(.*)$ http://%1.example.com/$1 [R=301,L]
# 2. rewrite http://host/site/<name>/<uri> => http://<name>.host/<uri>
RewriteCond %{HTTP_HOST} ^example\.com
RewriteCond %{REQUEST_URI} ^/site/([^/]+)
RewriteRule ^(.*) http://%1.example.com/$1 [R=301,NC,L]
# 3. internal redirect to the corresponding directory
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule ^(.*)$ site/%1/ [L,NC]
I receive a 500 server error instead.
Thanks in advance!
Just to clarify in your original question you said you need this redirection:
http://www.example.com/site/abc => http://abc.example.com/site/abc (**site/abc also present** in destination URL)
But later in your comment you suggested:
http://www.example.com/site/abc/xyz/part?id=123&name=lmn => http://abc.example.com/xyz/part?id=123&name=lmn (**site/abc missing** from destination URL)
Assuming your comment are right, please try this in your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule site/(.+)/(.*) http://$1.example.com/$2 [R=301,L]
This will redirect www.example.com/site/foo/bar* to foo.example.com/bar* with 301 status to the browser.
Assuming /site/abc/xyz/part is a actual physical file on disk try following (if actual file got some extension then append it).
Also add QSA flag so that query string is appended.
# 1. redirect uris which start with www. to the domain without www.
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.example\.com$
RewriteRule ^(.*)$ http://%1.example.com/$1 [R=301,L,QSA]
# 2. rewrite http://host/site/<name>/<uri> => http://<name>.host/<uri>
RewriteCond %{HTTP_HOST} ^example\.com
RewriteCond %{REQUEST_URI} ^/site/([^/]+)
RewriteRule ^(.*) http://%1.example.com/$1 [R=301,NC,L,QSA]
# 3. internal redirect to the corresponding directory
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule ^(.*)$ site/%1/ [L,NC,QSA]