Issue with rewriting rules

This is my project structure on localhost:


/www
  /mysite
    /img
    /js
    index.php
    proj.php
    styles.css
    .htaccess

In .htaccess
RewriteRule ^proj/([0-9]+)/$ proj.php?id=$1 [L]

The rule works fine. It converts localhost/mysite/proj.php?id=1 into localhost/mysite/proj/1/.

The problem then is that images, css and js files can’t be found by the browser. Is it possible to do something with rewrite rules to get around that, instead of using absolute paths?

RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)

Try something like that

Still the same problem.

You can use the HTML base tag to fix that :slight_smile:

Also, put this in the .htaccess


Options -MultiViews

This does not help with the problem you have now, but will resolve a problem you could have on another server that has MultiViews enabled. Servers that do have this enabled will serve proj.php when you request /proj/whatever, but this doesn’t use the RewriteRule. So it looks as if it does, but it doesn’t, and you don’t get your $_GET info. This is a royal PITA to debug, so I thought I’d give you a heads up :slight_smile:

The base url trick works fine. Thanks. :slight_smile: