1

I am trying to remove php extension from url, But its not working for me. I am using Windows 7, with apache2.2.17 and php5.3. Now I have configured it as

in .htaccess file

OPTIONS -Indexes IndexIgnore * Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME}.php -f RewriteCond %{REQUEST_URI} !/$ RewriteRule (.*) $1\.php [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ /$1 [R=301,L] 

in httpd.conf enabled mod_rewrite as

LoadModule rewrite_module modules/mod_rewrite.so 

and

<Directory "D:/Apache/htdocs"> Options Indexes FollowSymLinks ExecCGI MultiViews AllowOverride all Order allow,deny Allow from all </Directory> 

in php.ini

expose_php = On 

After making these configuration still i am not able to remove php extension from url in my windows machine but same thing is working in ubuntu server.

Is there anything I am missing here?

2 Answers 2

2

This might answer your question:

RewriteRule ^/([^-]*)$ /$1.php

It works for root catalog.

RewriteRule ^catalog/([^-]*)$ catalog/$1.php

Or you can write automatic script:

RewriteRule ^/([^-])/([^-])$ /$1/$2.php

But this is for "httpd.conf" file.

Where: ([^-]*) means variable; $1, $2 means converted to variable i.e.

www.verity.com/foo/bar => verity.com/foo/bar.php

Sign up to request clarification or add additional context in comments.

2 Comments

its working fine on ubuntu server, but not on my windows machine, Is there some configuration difference?
That was set up ON Windows Machine. I am using currently Windows Server 2008, with Apache 2.2.22 no-ssl **. Please wait, till I check config. **EDIT: Only httpd.conf file was modified. Nothing else. I will check other possibilities. Probably Apache is too old.
0

Use this instead:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php 

By doing this, you will be able to call example.com/abc.php as example.com/abc

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.