Forum Moderators: phranque

Message Too Old, No Replies

Redirect / Rewrite from Root

Redirecting requests to root index.htm*

         

jacobson

4:04 am on Mar 4, 2005 (gmt 0)



I have recently switched from static *.htm or *.html files to a script / database driven site. I want to redirect all requests to the root of www.mydomain.com or to index.htm or index.html in the root to a script at www.example.com/Merchant2/merchant.mvc. I do not want to redirect requests for any other filename in the root or for any files in any subdirectory, since I may request these files from my scripts or links generated by my scripts.

I have read through many posts and also the rewrite documentation, but I am not having success. My current effort is:

Options +FollowSymLinks
RewriteEngine on
# Rewrite all requests for "/" in root directory to index.html
RewriteCond %{REQUEST_URI} ^www\.example\.com/$
RewriteRule .* %1/index.html
# Rewrite requests for /index.html in root to Merchant2/merchant.mvc
# but only if the URL doesn't already include Merchant2/merchant.mvc
RewriteCond %{REQUEST_URI} !Merchant2/merchant\.mvc
RewriteCond %{REQUEST_URI} ^www\.example\.com/index\.html$
RewriteRule ^index\.html$ %1/Merchant2/merchant\.mvc [L]

Thanks.

[edited by: jdMorgan at 4:47 am (utc) on Mar. 4, 2005]
[edit reason] Obscured specifics per TOS. [/edit]

sitz

4:15 am on Mar 4, 2005 (gmt 0)

10+ Year Member



Why are you checking the incoming host header? Why not just do this:

RewriteEngine on
RewriteRule ^/($¦index.html?$) http://www.example.com/Merchant2/merchant.mvc [L,R]

I'm pretty sure that RewriteRule could be a bit cleaner, but I plead the lateness of the hour. =)

(Obviously, that double/broken pipe should be a solid pipe).

[edited by: jdMorgan at 4:48 am (utc) on Mar. 4, 2005]
[edit reason] Examplified. [/edit]