So I'm trying to use url rewriting to simplify url's on a website.
Example usage:
www.example.com/test -> www.example.com/index.php?page=test
www.example.com/test/x -> www.example.com/index.php?page=test&value=x
I use this for the rewriting:
RewriteEngine on
#Simplify url
RewriteRule ^(\w+)/?$ index.php?page=$1
RewriteRule ^test/(\w+)/?$ index.php?page=test&value=$1
The issue is that this approach seems to preserve the location prior to the rewrite. So other files loaded on the website like CSS are relative to the original location rather than the location after being rewritten.
Example:
www.example.com/test/x
rewrites to
www.example.com/index.php?page=test&value=x
.
But CSS files loaded when a user enters www.example.com/test/x
are loaded relative to the /test/
folder rather than the /
folder. So they're not found.
Am I doing something incorrectly? I'd assumed that rewriting would literally redirect, so things like this wouldn't be an issue. I'd like to solve this issue rather than just using absolute url's for everything - so I can still use it on my test server.