Redirecting Mod_rewrite
I think I finally figured out the basics of mod_rewrite, but I'm still having problems.
I want my hypothetical site to direct (almost) all traffic to home.html, which will parse SEO URLs. This means /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's the current setup:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !/something/I/want/to/preserve.html
RewriteRule ^(.*)$ /home.html [L]
It works brilliantly. Moreover, it works like a redirect: the URL becomes "/home.html" in the browser. How do I load the home page home.html but keep the url the same?
source to share
I think you should try to replace your rule with the following:
RewriteCond %{HTTP_HOST} =www.staging.example.com
RewriteRule ^$ /abc-sp.html [PT,L]
Note that the rule now runs an empty URL path test, so the original RewriteCond is not needed.
[PT] tells mod_rewrite to leave the output in "URL format" instead of converting it to a file path. This way the rewritten URL request can then be picked by mod_proxy and sent to your server.
This doesn't work, then use the [P] flag instead of [PT] and provide the url of your internal resource eg. "http://192.168.0.2:8080/abc-sp.jsp". The [P] flag generates an end-to-end end-to-end proxy, just like your existing mod_alias config code.
Please note that the above code is for .htaccess or for use in a config file in a container. If used outside of any container or .htaccess, add a leading forward slash to the RewriteRule template.
Hope my answer helps!: ~)
source to share
You should just add the flag P
to your RewriteRule
. See: Apache mod_rewrite User Guide
RewriteRule ^(.*)$ /home.html [PL]
source to share