I want write a rule in .htaccess for redirecting
http://www.dir.domain.com
http://dir.domain.com
http://www.domain.com/dir
these should redirect to
http://domain.com/dir
Thanks in advance...
The trick here is to use an .htaccess file in your DOCROOT
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?dir\.domain\.com$
RewriteRule ^.* http://domain.com/dir/$0 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^dir/.* http://domain.com/$0 [R=301,L]
Note that this is doing a 301 redirect -- that is the server tells the browser that this is a permanent redirect and the browser caches this redirect.
You can also do an internal redirect where this mapping is done silently at the server end by tweaking flags.
This assumes that your shared service is using Apache, if its using IIS, then you need to do something similar with the web.config
You can try:
RewriteCond %{HTTP_HOST} ^((?!www).+)\.domain\.com$
RewriteRule ^ http://domain.com/%1 [L,NE]
Please change domain by your domain, when you enter sub1.domain.com then it will redirect to domain.com/sub1, when you enter sub2.domain.com then it will redirect to domain.com/sub2 ....
Related
I am updating the Iirf.ini file to redirect sub.columbia.edu to giving.columbia.edu/video.
sub.columbia.edu is already redirecting to giving.columbia.edu.
How can I go one step further to redirect it to giving.columbia.edu/video.
Important Note: I would like the URL to show as sub.columbia.edu in the browser and not as giving.columbia.edu/video
#Redirect subdomain to specific URL
RewriteCond %{HTTP_HOST} ^sub\.columbia\.edu
RewriteRule ^/$ /video
The above doesn't work. Any ideas how I should modify this?
Thank you!
You can try this and see how it works for you.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.columbia\.edu
RewriteRule ^(.*) http://giving.columbia.edu/video [L,R=301]
Or you can do a redirect, this should work also.
Redirect 301 / http://giving.columbia.edu/video
I have a domain like:
this.that.com
(it can also be accessed from:)
that.com/this
What I would like to do is make it so that the server transfers all requests from the two above url's to:
this.com
I need it so if I type in this.that.com
it will auto transfer to this.com
thanks in advance.
To redirect all requests to this.com, match everything, which is not already this.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^this\.com$
RewriteRule .* http://this.com/$0 [R,L]
If you want to redirect to the main page instead, leave out the URL path
RewriteEngine On
RewriteCond %{HTTP_HOST} !^this\.com$
RewriteRule .* http://this.com/ [R,L]
If everything works as expected, you can switch to R=301 redirection.
I've a domain like example.com. I want to all the traffic on it to be sent to sub.example.com.
Currently I'm using this code but it sends to example.com/sub:
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteCond $1 !^sub
RewriteRule ^(.*)$ /sub/$1 [L]
Is there a way to do this?
I think you have to use the R flag: Forces an external redirect, optionally with the specified HTTP status code. details...
RewriteRule (.*) http://... [L,R]
Just put the following code in to your .htaccess file.
Redirect 301 / http://sub.domain.com
Remember to change http://sub.domain.com to your sub-domain.
Connor
My server is somehow configured to accept any string as a existing subdomian. This subdomains doesn't redirect, they show content instead. For example:
bla.example.com // shows the content of http://example.com
blabla.example.com // show the content of http://example.com
lorem.example.com/events/ // shows the content of http://example.com/events
So you can use "stackoverflow.example.com" and it will work.
I want to create an .htaccess rule to overwrite this behavior. I want to redirect http://*.example.com/* to http://www.example.com/*
Everything I have done so far is redirect http://example.com to http://www.example.com (wich is another behavior I want to keep)
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Thank you for your help!
Try adding the following to your htaccess file in the root folder of your domain
RewriteEngine on
RewriteBase /
#if its not www.example.com
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
#redirect it to www.example.com
RewriteRule .* http://www.example.com%{REQUEST_URI} [R=301,L]
I've got a very simple .htaccess file that enables the rewrite engine, and lets me use URI's in my web applications.
The problem is i need to do a 301 redirect to get my webaddress without www redirected to my website WITH www (While keeping the current rewrite function that redirects every subdirectory access to index.php in the root of my domain), to optimize seo. I just can't get it to work. :(
So in short terms i need to combine the current code which is:
RewriteEngine on
RewriteRule ^(.+)/$ index.php
With the 301 rewrite rule which is
RewriteEngine on
RewriteCond %{HTTP:Host} ^website\.com$
RewriteRule (.*) http\://www.website.com$1 [NC,R=301]
My server is running Apache, with the mod rewrite enabled.
Thanks in advance
You don't make it entirely clear except in your example that your using php, however, using Helicon ISAPI Rewrite for IIS / .NET I use:
RewriteCond %{HTTP:Host} ^website\.com$
RewriteRule (.*) http\://www.website.com$1 [NC,R=301]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Reference: http://www.rlmseo.com/blog/htaccess-rewrite-www/