I have a domain "example.com" and i use following redirection code to redirect it to www in .htaccess file
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
it is working fine until i generate a sub-domain with that domain like "abc.example.com" but it's getting conflicts with htaccess and redirecting the sub-domain to "www.abc.example.com/abc/"
You can use:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|abc)\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Related
I already added a subdomain wildcard to my dns (*.domain.com) but now i can't get the rule right.
I want
subdomain.domain.com
to point to
domain.com/subdomain
my htaccess file is :
RewriteEngine On
RewriteCond %{HTTP_OST} ^(?:www\.)?((?!www\.)[^.]+)\.(domain\.com)$ [NC]
RewriteRule ^/?$ http://www.%2/%1 [R=302,L]
but i'm getting Internal Server Error.
How can i get it to work ?
If you want it to actually redirect then you can do this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/subdomain/$1 [R=301,L]
If you don't want it to redirect and keep subdomain.example.com in the address bar then, you can do this.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com [NC]
RewriteRule ^(.*)$ /subdomain/$1 [L]
What should I put in .htaccess to redirect all links from main domain to subdomain? I have it like that but it doesnt wok:
RewriteCond %{HTTP_HOST} ^http://example.com/$
RewriteRule ^(.*)$ http://subdomain.example.com/$1 [R=301,L]
Have you tried without the http:// and the / at the end in the first line ?
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ http://subdomain.example.com/$1 [R=301,L]
I need to redirect this URL: http://www.africafreak.com/blog/sitemap.xml into http://africafreak.com/blog/sitemap.xml using .htaccess file
Please help me
If your website is hosted on an apache server, a redirect from www to non-www is a simple implementation. Add the following to your .htaccess file.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^domain\.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]
or try this:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
I have searched the web all over for a good generic .htaccess script for redirecting non-www to www, and currently i'm using this:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
This works fine, but if i go to a subdomain www. will be added. Does anyone has a good working redirect .htaccess script?
Try this :
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^([^\.]+)\.([^\.]+)\.([a-z]{2,4})$
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
#Vince What if the requested url is something like:
http://www.abc.example.com
IMHO, I think with your method it would never be redirected to:
http://www.example.com
How about this?
# Rewrite domain
RewriteCond %{HTTP_HOST} !^www\.([a-z1-9\-]+)\.([a-z]+)$ [NC] [and]
RewriteCond %{HTTP_HOST} ([a-z1-9\-]+)\.([a-z]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1.%2/$1 [R=301,L]
Also, you guys may find these references useful:
https://www.drupal.org/node/93603
http://www.askapache.com/htaccess/modrewrite-tips-tricks.html
I have this application directory
http://www.example.com/application
When user browse without www, (e.g. example.com/application), i want to force and redirect them to http://www.example.com/application
How can i achieve using .htaccess.
Thank you.
To redirect non www to www:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
To redirect www to non www, the code is similar:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^my-domain\.com$ [NC]
RewriteRule ^(.*)$ http://my-domain.com/$1 [R=301,L]