Reputation: 3587
I think I finally got the basics of mod_rewrite figured out, but I am still having some trouble.
I want my hypothetical site to direct (almost) all traffic to home.html, which will parse the SEO URLs. This means that /home, /home.html, /index.html, /something/somethingelse/gobledegook all go to home.html (don't worry about passing GET variables, the home file will parse the entire URL later).
Here is the current setup:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !/something/I/want/to/preserve.html
RewriteRule ^(.*)$ /home.html [L]
This works brilliantly. Except it works as a redirect: the URL in browser becomes "/home.html". How do I load the home.html page but keep the URL the same?
Upvotes: 3
Views: 232
Reputation: 2099
You should be able to simply add the P
flag to your RewriteRule
. See: Apache mod_rewrite Manual
RewriteRule ^(.*)$ /home.html [PL]
Upvotes: 1
Reputation: 18446
Simple, use the passthrough (PT) flag:
RewriteRule ^(.*)$ /home.html [PT,L]
Upvotes: 2
Reputation: 419
I think you should try to replace your rule with this:
RewriteCond %{HTTP_HOST} =www.staging.example.com
RewriteRule ^$ /abc-sp.html [PT,L]
Note that the "blank URL-path" test is now done in the rule, so the original RewriteCond is not needed.
The [PT] tells mod_rewrite to leave the output in "URL-format" instead of converting it to a filepath. Thus the rewritten URL-request can then be picked up by mod_proxy and sent to your back-end.
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 container. If used outside any container or .htaccess, add a leading slash to the RewriteRule pattern.
Hope my answer helps! :~)
Upvotes: 1