干净的永久链接从URL删除php扩展

时间:2019-09-19 02:40:03

标签: php regex .htaccess mod-rewrite url-rewriting

我希望使用干净的网址,以便为访问者提供http://localhost/MYEVENTS/filename/而不是http://localhost/MYEVENTS/filename.php

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /MYEVENTS/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /MYEVENTS/index.php [L]

    RewriteRule ^([a-z]+)\/?$ $1.php [NC]

</IfModule>

1 个答案:

答案 0 :(得分:0)

尝试一下

RewriteEngine On

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