VSG24 VSG24 - 1 year ago 65
PHP Question

mod_rewrite issues and php

I'm trying to convert my app links, so that a link like this:


gets converted to this:


so far I was able to do it using:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?id=$1&category=$2&title=$3 [QSA,L]

but that completely breaks links to css and other files as it redirects every request with query to index.php

so I changed it slightly so that it only runs when the first query is a number:

RewriteEngine On
RewriteRule ^([0-9]*)/([^/]*)/([^/]*)$ /index.php?id=$1&category=$2&title=$3 [QSA,L]

this one doesn't break css and js files, however when you go to the link for example
then try to go to another link like
by clicking on it inside the previous page it will instead redirect you to something like

How do I achieve what I described without any of these weird side effects??

Answer Source

Use :

RewriteEngine On
RewriteRule ^([0-9]+)/([^/.]+)/([^/.]+)/?$ /index.php?id=$1&category=$2&title=$3 [QSA,L]

And add this code to your html <header>:

<base href="/">


<base href="http://www.domain.com/">

To fix relative css and js links

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download