Jump to content

modification rewrite doesn't work


jackmaessen

Recommended Posts

Hello,

I am trying to remove my .php extensions with rewrite_mod.

I use this code in my .htaccess file which is in the webroot:

 

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}.php -f

RewriteRule ^(.*)$ $1.php

 

In my apache httpd.conf file, i removed the # sign from the LoadModule

 

But it is still not working for me

Can anyone tell me why it does not work?

Link to comment
https://forums.phpfreaks.com/topic/272849-modification-rewrite-doesnt-work/
Share on other sites

You have special characters in most if not all computer languages that represent something. In this case a dot/period/. - in the second condition - matches the requested file name, followed by some character, followed by "php".

 

E.g. "myfilexphp", "myfile4php", "myfile:php" are all valid but technically incorrect.

 

To ensure it matches a dot only you must escape the special character; this applies to every special character. This can be done by using a backslash although it may be another character in some languages (I'm yet to see one where its not a backslash). So your condition should read:

 

RewriteCond %{REQUEST_FILENAME}\.php -f

that also doesnt work

 

my code:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

 

I tried also a space between } and \, but gives me a 500 server error

RewriteCond %{REQUEST_FILENAME} \.php -f

 

i have tried so many things, but nothing seems to work

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.