Jump to content

PHP Includes Trouble with mod_rewrite!


dooper3

Recommended Posts

I am using mod_rewrite to change this: profiles.php?id=3 to this: profiles/3 by have a .htaccess file in the document root with the following code:

RewriteRule ^profiles/([0-9]+) /profiles.php?id=$1 [QSA,L]

It works fine, but it creates the problem that the PHP includes for the navigation, footer etc. then don't work as they are in a folder in the root directory called "includes", and the browser is trying to look in "profiles/includes" which of course doesn't exist (nor does the folder profiles, it's just created by the rewrite rule.

 

Rather than going round all the pages and changing all the includes to the entire domain name and folder they need to link to etc, is there a quick fix that will work site wide? A rewrite rule would be brilliant, or any other method gratefully accepted!

 

Thanks,

Charlie

Link to comment
https://forums.phpfreaks.com/topic/36944-php-includes-trouble-with-mod_rewrite/
Share on other sites

Likely would be best using conditions to check if the files exist before the rewrite and only use the rule if they don't.  This would be accomplished with this I believe:

 

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^profiles/([0-9]+) /profiles.php?id=$1 [QSA,L]

 

If it's PHP that the problem is occurring with using the include() statement this does not have anything to do with the browser so you'll need to check your include statements.

 

Hope this helps,

 

Dest

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.