basically what im trying to do it :
http://mydomain.com/1/1
to
http://mydomain.com/index.php?mid=1&mpid=1
and im using these codes in htaccess.
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+) index.php?mid=$1&mpid=2 [NC]
it works fine but the problem is that css get messed,its not loading css and images. whats the solution ?
The problem is that your CSS is no longer relative to the root of your site.
Your index.php
file is at /
, but when you rewrite to /1/1
, the client thinks you actually are at /1/1
, and looks for the CSS file relative to that path, as it should.
What you need to do is reference your CSS at the root, /style/something.css
or whatever it is. Just make sure you have /
at the front of that path.
There can be two problems:
CSS and Images are not loading at all
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz)$
RewriteRule ^([^/]+)/([^/]+) index.php?mid=$1&mpid=2 [NC]
Or the images now have different path. Always put slash at the beginning of the path, it will help. Especially in CSS file, where the path is taken relative from CSS file, not actual url.
Use the base
element to set the base URL for all assets (CSS and images, etc). Here's the docs: https://developer.mozilla.org/en/HTML/Element/base
<base href="http://www.yourdomain.com/">
Also, your .htaccess may be redirecting the calls for your CSS and images. Change your .htaccess to this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+) index.php?mid=$1&mpid=2 [NC]
... that will check to make sure the requested file (-f
) and the requested directory (-d
) don't exist before doing any redirects.
Maybe the sript sends the wrong Content-Type. CSS-Data requires Content-Type: text/css
.
PHP:
header("Content-Type: text/css");
With a file extension like '.php' no browser will sniff it correct.
Prepend
RewriteCond %{REQUEST_FILENAME} !-f # Existing File
before your RewriteRule - it prevents existing files, like css files, from being rewritten.