Rihan
Rihan

Reputation: 31

Htaccess for url rewrite with one variable

RewriteRule page/([0-9]+)$ page.php?id=$1

It works, but the included links like css or js don't work. page/ is seen like a folder, so the links (example: <link rel="stylesheet" type="text/css" media="screen" href="css/default.css" />) aren't found.

Another example: if "id" doesn't exist i do this ErrorDocument 403 /notfound.php, but you are redirected to domain.com/page/notfound.php. How i can solve this problem?

Upvotes: 1

Views: 114

Answers (1)

Oussama Jilal
Oussama Jilal

Reputation: 7739

Try this instead :

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule page/([0-9]+)$ page.php?id=$1

This will redirect only if the requested file or directory does not realy exists.

More informations on mod_rewrite here

Edit :

As for you issue with resources not beeing found, you will have to add the base tag to you head section in you html page :

<base href="/">

More informations about the base tag here

Upvotes: 2

Related Questions