Forum Moderators: phranque
I am trying to do a 301 redirect and I would need to do that without changing the URL in the address bar.
Here is the rule I have:
RewriteCond %{HTTP_HOST} ^www\.staging\.example\.com$
RewriteCond %{REQUEST_URI} !^.. (This is to indicate that the rule should be executed if there is nothing after www.staging.example.com)
RewriteRule ^(.*) http://www.staging.example.com/example-sp.html [R=301,L]
Result:
Changing the URL to http://www.staging.example.com/example-sp.html when I invoke www.staging.abc.com.
Other Trials made on the third line:
1. RewriteRule ^(.*) http://www.staging.example.com/example-sp.html
Result: Same as above
2. RewriteRule ^(.*) /example-sp.html [R=301,L]
Result: Same as above
3. RewriteRule ^(.*) /example-sp.html
Result: 404 (This is because example-sp.html doesn't exist in document root. Any *-sp.html will pick *-sp.jsp from the app server)
4. No rule
Result: It picks the default index.html
Please help.
Thanks
Abhilash
[edited by: Abhihome at 7:10 pm (utc) on Jan. 8, 2010]
[edited by: jdMorgan at 2:29 am (utc) on Jan. 9, 2010]
[edit reason] example.com [/edit]
RewriteCond %{HTTP_HOST} =www.staging.example.com
RewriteRule ^$ /abc-sp.html [PT,L]
It that doesn't work, then use the [P] flag instead of [PT], and specify the *URL* of your back-end resource, e.g. "http://192.168.0.2:8080/abc-sp.jsp". The [P] flag will generate a reverse-proxy through-put, just as your likely-existing config-file mod_alias code does.
Note that the code above is for .htaccess or for use in a config file *within a <directory> container*. If used outside any <directory> container or .htaccess, add a leading slash to the RewriteRule pattern.
Jim