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/
Related
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 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!
I'm looking for a way to do something like this in .htaccess:
This.is.my-website.com
Please note: This.is is the rewrite to the directory This.is and mywebsite.com is the URL of the site. I want all requests to the site to be redirected to that folder (301?). Is it possible to achieve this in .htaccess?
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.my-website.com$ [NC]
RewriteRule ^(.*)$ /%1/$1 [L]
for an internal rewrite (won't change the URL in browser's address bar).
Or to externally redirect:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.my-website.com$ [NC]
RewriteRule ^(.*)$ http://my-website.com/%1/$1 [L,R=301]
Basically I want sub.domain.com to redirect to domain.com, but only that url. For example sub.domain.com/page should still load without redirecting. How can I do this .htaccess?
Your .htaccess should look like
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule .* http://domain.com [R,L]
This should work within .htaccess placed in the root directory. The empty rule (nothing between ^$) is interpreted as / (the root). Your subpages and subdirectories should remain unaffected. Requires mod_rewrite.
RewriteEngine on
RewriteRule ^$ http://new.domain.com/ [L]
# subdomain home page to main domain page
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule .* https://www.example.com [L,R=301]
This works for me as I wanted to have 301 redirect and to https main domain page. I hope this helps. Thanks..
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]