Root redirect that ends at the root level

New to mod_rewrite? This is a good place to start.

Root redirect that ends at the root level

Postby sam.webb » Tue Sep 29, 2009 1:59 am

Hi,

I've been trying to get a Mod_Rewrite going for a couple of days now and have got nowhere.

We recently moved domain's and started using a CMS. However not all of the content has been moved so we need to put som redirects in place.

All the redirects are currenltly working and created by someone else. I need to add a redirect to the root level which will not affect the subfolders / other redirects.

subdomain1.r.com - Original site
subdomain.1.s.com - New site
subdomain2.s.com - Copy of the old site

subdomain1.r.com needs to redirect to subdomain1.s.com. However this musn't affect the redirects that are in place such as

subdomain1.r.com/training -> subdomain2.s.com/training

Can I either make a redirect that only trainsfers http://subdomain1.r.com to http://subdomain1.s.com and will not take http://subdomain1.r.com/training ?

I guess there are 2 options

Option 1: Set up all the redirect in the httpd.conf file
Option 2: Make a redirect that deson't pass on o the sub folders?

Your help is appreciated.

Thanks
sam.webb
 
Posts: 2
Joined: Tue Sep 29, 2009 1:26 am

Postby richardk » Tue Sep 29, 2009 2:47 pm

[^/]+ can be used to not match slashes (and therefore sub directories).

Try
Code: Select all
RedirectMatch 301 ^/[^/]+$ http://subdomain.1.s.com$0

or
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?subdomain1\.r\.com$ [NC]
RewriteRule ^/[^/]+$ http://subdomain.1.s.com$0 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sam.webb » Wed Sep 30, 2009 1:08 am

Thank you for reply, this is where I make it more confusing

On my apache local server using the RedirectMatch results in only sub folders being redirected, the root displays the page as normal. I placed it in a root level .htaccess file.

Code: Select all
RedirectMatch 301 ^/[^/]+$ http://www.isis.stfc.ac.uk$0




On the windows based IIS server using ISAPI_Rewrite it doesn't like the (sorry forgot to mention I was using that)

Code: Select all
Options +FollowSymLinks



In apache this does nothing, and on IIS taking out the Options +FollowSymLinks also results in nothing occuring.

[code]Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?subdomain1\.r\.com$ [NC]
RewriteRule ^/[^/]+$ http://subdomain1.s.com$0 [R=301,L]/[code]



I got this to work however it needs tweaking to also send specified files such as index.html

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.isis.\rl\.ac.uk$ [NC]
RewriteRule ^(.*)[/]$ http://www.isis.stfc.ac.uk/ [R=301,L]


Thanks for your help, it seems to have nearly got me there :)
sam.webb
 
Posts: 2
Joined: Tue Sep 29, 2009 1:26 am

Postby richardk » Wed Sep 30, 2009 12:51 pm

Try
Code: Select all
RedirectMatch 301 ^/[^/]*$ http://www.isis.stfc.ac.uk$0

The + means there must be one or more (of [^/]) whereas * allows for none (or more).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 35 guests

cron