Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

htaccess rewrite all except index.html

Status
Not open for further replies.

Geronantimo

Technical User
Apr 3, 2006
79
SE
I have an existing website that will now be moved to a subdomain. I would like to use rewrite rules to redirect all of the requested pages to the subdomain apart from the index.html and requests that come to the website using just the domain name (without index,html)

I have got as far as writing the condition to rewrite to the subdomain:

Code:
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^[URL unfurl="true"]www.domain.com$[/URL]
RewriteRule ^(.*)$ [URL unfurl="true"]http://sub.domain.com/$1[/URL] [R=301,L]

However, I am have been unable to add the condition that excludes the index.html. This does not seem to work:

Code:
rewriteCond %{REQUEST_URI} !^index.html
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^[URL unfurl="true"]www.domain.com$[/URL]
RewriteRule ^(.*)$ [URL unfurl="true"]http://sub.domain.com/$1[/URL] [R=301,L]

But this isn't the only problem; I don't know how to exclude requests that come to (with just the slash)

Could somebody please give me some suggestions?
 
Follow up,

I have this working to redirect all requests apart from "index.html":
Code:
RewriteCond $1 !^index\.html$
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^[URL unfurl="true"]www.domain.com$[/URL]
RewriteRule ^(.*)$ [URL unfurl="true"]http://sub.domain.com/$1[/URL] [R=301,L]
The only part that I have not worked out is how to prevent the redirect for requests that are made to domain.com or with only the trailing slash
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top