Jump to content

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
Edited by cpd

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

Edited by jackmaessen
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.