htaccess - 根据网址

时间:2015-06-03 21:25:55

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

我有以下规则为所有请求添加.html,以便用户导航到www.mysite.com/support时,他们会看到我的www.mysite.com/support.html页面:

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

如何更改此设置,以便对于特定网址,它会添加.php而不是.html:

  • / support =>应该访问www.mysite.com/support.php
  • / contact =>应该访问www.mysite.com/contact.php
  • / everything else =>应该去www.mysite.com / ... html

感谢。

1 个答案:

答案 0 :(得分:0)

我会将您的.htaccess更改为:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^support /support.php [L]
RewriteRule ^contact /contact.php [L]
RewriteRule ^(.*)$ $1.html