I want to make a URL change whenever clients access my website with example.com to wwww.example.com I have used .htaccess for this but it works not correct.
Because now a-z0-9.example.com wil also redirect to www.example.com, I want this only works for example.com than redirect to www.example.com
.HTACCESS
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.eample.com/$1 [L,R=301,NC]
Make another .htaccess for a-z0-9.example.com with the code bellow:
RewriteEngine on
RewriteCond %{HTTP_HOST} a-z0-9.example.com [NC]
RewriteRule ^(.*)$ http://www.a-z0-9.example.com/$1 [L,R=301,NC]
I think this will work.
Good Luck!
Related
I've got the following code that will redirect "www.domain.com" to "domain.com". This is fine but I want it to redirect all subdomains, ie. "test.domain.com" to "domain.com" as well. It has to be dynamic, meaning that the domain name can't be hardcoded.
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
I've tried various stuff but I can't get it to work.
This will do it:
RewriteCond %{HTTP_HOST} ^[^.]+\.([^.]+\.[^.]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
It supports anything.example.com and redirects to example.com and example.com can be served on the same site using the redirect.
I have a big issue here.
I have a site example.com, due to the way it was coded, example.com is different from example.com/index. How can i use htaccess to redirect all incoming request from example.com to example.com/index
Here is what i've tried to do but it's not working
The first i did was
RewriteRule ^(.*)$ http://%1/index/$1 [R=301,L]
The second was
RewriteRule ^/index/([^/.]+)/?$ index.php [L]
I'm not so familiar with htaccess though. Any help?
Thanks
NOTE there are so many domain the .htaccess file is working for and i want the rule to affect all e.g example.com should go to example.com/index, example1.com should go to example1.com/index and ... like that
And i already have this rule on top RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
You can use this single rule in the website root .htaccess:
RewriteEngine On
RewriteRule ^/?$ /index [L,R=302]
This will redirect:
example.com => example.com/index
example1.com => example1.com/index
RewriteCond %{HTTP_HOST} =example.com [NC]
RewriteRule ^(.*)$ http://example.com/index.php/$1 [R=301,L]
I moved my site from blog.abc.com to www.abc.com
I want to redirect every request made to blog.abc.com to abc.com
For example:
If blog.abc.com/example.html is requested, it should redirect to www.abc.com/example.html, how can I do it via .htaccess only?
You can put this code in your htaccess (in blog.abc.com root folder)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
Using mod_rewrite you could do it like this:
RewriteEngine On
RewriteCondition %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R,L]
or if blog.example.com has its own vhost you could also use mod_alias:
Redirect / http://example.com/
Im migrating my website from the .co.uk to the .com but need to setup a 301 redirect so all of the individual pages will still be routed properly.
ie i want http://www.mydomain.co.uk/shopping/product1 to go to http://www.mydomain.com/shopping/product1
I have done this before but for the life of me cannot remember how.
many thanks
paul
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
This redirects both the www and non-www for mydomain.co.uk to www.mydomain.com.
To redirect any (sub-)domain other than mydomain.com, use
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
Might be useful if you have other domains pointing to the same website.
It also redirects the www.mydomain.com to mydomain.com.
This is accomplished using a simple rewrite placed in your .htaccess file.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.co.uk$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
I would like to modify my .htaccess file so that when someone comes into my site without typing www the site always redirects them to the www version. For example, if my url is www.abc.com and they just type abc.com, I want to redirect them to abc.com.
Here is my current htaccess file:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Normally I know how to do the redirect, but im having issues since it already has those few lines in there.
I use the code below. It can be used for any domain name. You just need to enter it in your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
(edited to have all the code in the same block)
Add something like this immediately after RewriteEngine on:
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
There are two methods available
1) use mod_alias apache module
Redirect permanent /something http://yourwebsite.com/something
2) Add the following entry in your .htaccess / http.conf / yourwebsite.conf in the webserver configuarion directory
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourwebsite.com
RewriteRule ^(.*)$ http://www.yourwebsite.com$1 [R=permanent,L]
If you want redirect example.com to www.example.com you can try below code
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]