Question

I'm trying to create a mod_rewrite ruleset in .htaccess so that I can create some flat links to functionality in a page.

When the user enters: http://example.com/where/location

I want to redirect to : http://example.com/index.php?where=location

I'm currently using:

RewriteEngine on
RewriteRule ^where/([^/.]+)/?$ /index.php?where=$1

which kind of works, except that css, JS and image links in index.php are no longer found - it's as though the server is serving index.php up from the non-existant /where/location sub-directory.

Is this what's happening and is there a way to case the server to serve index.php with relative links from its actual location in the root directory normally?

Was it helpful?

Solution

The server side is irrelevant here. You are in fact serving the site from /where/location; it's irrelevant that this URL is getting rewritten internally. If you're using relative paths to CSS files, the browser is resolving those against the current URL that it is on. The best strategy is typically to use absolute paths for included files, e.g.:

/css/style.css

instead of

css/style.css
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top