how i can delete .php from url with mod_rewrite?
for example: test.com/index.php -> test.com/index/ test.com/contact.php -> test.com/contact/
tanks a lot
how i can delete .php from url with mod_rewrite?
for example: test.com/index.php -> test.com/index/ test.com/contact.php -> test.com/contact/
tanks a lot
RewriteEngine on
RewriteRule ^([^/]+)/?$ $1.php
If the user typed in http://example.com/index/
they would get the actual page of http://example.com/index.php
Basically this rule says "match everything from the base url up to a slash, or the end if no slash, but not including the slash. Then give the user that matched part with .php appended to the end."
This is only going to work for the first level of directory; ie. this will not match on example.com/index/some/other/stuff
- no redirect there.
If you really want to redirect requests to /index.php
to /index/
, try this rule:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ (/[^?\ ]+)\.php[?\ ]
RewriteRule .+\.php$ %1/ [L,R=301]
And for the other direction:
RewriteRule (.+)/$ $1.php [L]
You can also use both rules at the same time to get this behavior:
/index.php
are getting redirected externally to /index/
/index/
are getting rewritten internally to /index.php