I have some mod rewrite which will remove the .php and format a certain page called county.php.
My problem is with the part that rewrites the county.php. I have to put a ‘/’ in front of all the links to css, images and js files. This causes problems on other parts of the site as I use php includes. Is there away around this? Thanks
RewriteEngine On
RewriteRule ^county/([^/\.]+)/?$ county.php?county_id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php
If you are using mod_rewrite to create virtual folders you have to deal with different folder names for all additional media types (CSS, JS, images …). To deal with a dynamic number of folders or even some pages with folders and some without makes it more complicated.
I see following ways to solve that:
use always the same number of folders (folder depth) – or
do not use / character for separating parameters (e.g. “county_xzy”) – or
create mod_rewrite rules for your media files as well
Example: