Remove php extension from url

2019-03-05 12:16发布

I have url example.com/lt.php/example and want remove .php that will be example.com/lt/example
I try with htacces, but I think that's impossible

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://moliplante.com/folder/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]

RewriteRule ^([^/.]+)$ $1.php [L]

2条回答
你好瞎i
2楼-- · 2019-03-05 12:48

Try this, hope it will work

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php
查看更多
beautiful°
3楼-- · 2019-03-05 13:04

This might work:

 RewriteRule ^(.+)\.php/(.+)$ $1/$2

The first backreference would capture lt from lt.php and the second backreference would have example and php would be added to it.

查看更多
登录 后发表回答