如何使用.htaccess url重写添加.php扩展名?

时间:2012-01-10 06:19:48

标签: php .htaccess url-rewriting

我在我的网站上设置了.htaccess文件,该文件在URL中显示SLUG文本作为页面名称但没有扩展名。 例如真正的网址是

www.mywebsite.com/page.php?page=about-us

然后通过url重写

加载到url下面
www.mywebsite.com/about-us

以下是我的.htaccess文件代码

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !^.*(images/|\.js|\.css).*$ [NC]
RewriteRule ^([a-zA-Z0-9_-]+)$ /page.php?page=$1

现在我想在所有页面上显示.php扩展名,以便网址应如下所示

www.mywebsite.com/about-us.php

我该怎么做?

2 个答案:

答案 0 :(得分:2)

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_URI} !^.*(images/|\.js|\.css).*$ [NC]
RewriteRule ^([a-zA-Z0-9_-]+)\.php$ /page.php?page=$1

答案 1 :(得分:0)

RewriteEngine On

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

php_flag display_errors on