I want that when user input http://example.com/abc/123/jon/ in URL is actually show this file http://example.com/abc.php?id=123&name=jon and this is easily can be done by adding these lines into htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^abc/(.*)/(.*)/ abc.php?id=$1&name=$2 [L]
but my abc.php file having some (css, js) files:
<link href="css/style.css" rel="stylesheet">
<script src="js/jquery-1.10.2.js"></script>
and images like : img/logo.png
but because of my .htaccess file it is searching for style.css here : http://example.com/abc/123/jon/css/style.css instead of http://example.com/css/style.css and similarly for js and images.
i already tried many similar answers here but none of them working for me.i am looking for .htaccess solutions for this.
You can use that:
RewriteEngine on
# not rewrite css, js and images
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^abc/(.+)/(.+)/ abc.php?id=$1&name=$2 [L]
# rewrite css, js and images, from root
RewriteRule ^abc/[^/]+/[^/]+/(.+)$ $1 [L]
If your final css (or js) directory is not at root, you can add the path before the last $1
. Now it's: /css/style.css
with /abc/xxx/yyy
/css/style.css
Just add before the RewriteRule
one line:
RewriteCond %{REQUEST_FILENAME} !-f
This means that if your request uri points at existing file, then next RewriteRule
will not trigger.
If you want other way then this one should do:
RewriteCond %{REQUEST_FILENAME} !\.(css|js|png|jpg)$
You can add more extensions separated by pole (|
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With