I'm trying to set up some path rewrites on two separate servers, one using mod-rewrite on Apache and one using HttpRewriteModule on Nginx. I don't think I'm trying to do anything too complex, but my regex skills are a little lacking and I could really use some help.
Specifically, I'm trying to transform a formatted URL into a query string, so that a link formatted like this:
http://www.server.com/location/
would point to this:
http://www.server.com/subdirectory/index.php?content=location
Anything extra at the end of the formatted URL should be appended to the "content" parameter in the query string, so this:
http://www.server.com/location/x/y/z
should point to this:
http://www.server.com/subdirectory/index.php?content=location/x/y/z
I'm pretty sure this should be possible using both Apache mod-rewrite and Nginx HttpRewriteModule based on the research I've done, but I can't see to get it working. If anyone could give me some pointers on how to put together the expressions for either or both of these setups, I'd greatly appreciate it. Thanks!
In nginx you match "/location" in a rewrite directive, capture the tailing string in the variable $1 and append it to the replacement string.
server {
...
rewrite ^/location(.*)$ /subdirectory/index.php?content=location$1 break;
...
}
In Apache's httpd.conf this looks quite similar:
RewriteEngine On
RewriteRule ^/location(.*)$ /subdirectory/index.php?content=location$1 [L]
Have a look at the examples at the end of this page: https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With