.htaccess目录的RewriteRule

时间:2014-04-22 20:56:10

标签: regex apache .htaccess mod-rewrite

我想将RewriteRule用于以下

www.mysite.com/xyz
or
www.mysite.com/xyz/

==>应该访问www.mysite.com/page.php?var=xyz

www.mysite.com/xyz.html
www.mysite.com/xyz.htm
www.mysite.com/xyz.php
or any other extension

==>不应该改写

只有在没有文件扩展名时,才应使用重写规则 谢谢!

1 个答案:

答案 0 :(得分:0)

将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

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