Htaccess从url中删除文件名

时间:2016-03-01 06:38:43

标签: .htaccess

我想删除single.php?我怎么会这样做?,我尝试过以下几点:

所以EG。 www.mysite.com/single.php/contact /

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^([^\.]+)$ $1.php [QSA,NC,L]
</IfModule>

1 个答案:

答案 0 :(得分:0)

您可以使用以下规则:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ single.php/$1 [L]