Mahdi
Mahdi

Reputation: 335

not rewrite css or js or image files htaccess

I have a url like this:

mysite.com/1/everything

and I want to rewrite it and only get the number in the url (e.g. 1 above). For that, I have written a htaccess like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule for root pages
RewriteRule (^\d+\/?([\x00-\x7F]|[^\x00-\x7F])+\/?$) index-continue.php?id=$1 [NC,L,QSA]

But all of my css files and image files and js files get rewritten! How can I solve this problem? This causes all the file rewrites on the wrong path.

Upvotes: 0

Views: 196

Answers (2)

Amit Verma
Amit Verma

Reputation: 41219

To fix the css and js path on rewritten urls, you need to add the following base tag to the head section of your webpage :

<base href="/">

Related :

Seo Friendly Url css img js not working

Upvotes: 0

Sarvagna Mehta
Sarvagna Mehta

Reputation: 340

Your .htaccess file should only keep the following thing, it will allow your js and css to open directly with the path root/css/file.css and root/js/file.js

RewriteEngine On
RewriteRule ^style/([^/.]+)?$ style/$1
RewriteRule ^js/([^/.]+)?$ js/$1
RewriteRule ^([^/.]+)/([^/.]+)?$ index-continue.php?id=$1&%{QUERY_STRING}

Upvotes: 1

Related Questions