Eyad Fallatah
Eyad Fallatah

Reputation: 1948

.htaccess clean URL and relative paths

I have the following in my .htaccess which is :

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /index.php?type=cat&id=$1 [QSA,L]
RewriteRule ^page/([^/]+)$ /index.php?type=page&name=$1

This seems to work just fine but relative paths to pictures and css files inside of index.php become broken in the second case (Page). did not work. In second case, all images are pointing to page/images/ instead of image/

Other than hardcoding the actual path to images, is there any other way to fix this?

images, css, js folders are located in the root. This is how the root looks like

.htaccess
index.php
images/
css/
js/

Upvotes: 3

Views: 2284

Answers (1)

Ulrich Palha
Ulrich Palha

Reputation: 9509

RewriteCond directives only apply to the rule directly following them.Try the follwing

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /index.php?type=cat&id=$1 [QSA,L]

RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^page/([^/]+)$ /index.php?type=page&name=$1 [L]

#rewrite requests for page/images to images
RewriteCond %{REQUEST_URI} ^/page(/images/.+)$ [NC]
RewriteRule . %1 [L]

EDIT. Modified to rewrite page/images to images

Upvotes: 6

Related Questions