问题
I would like to use the RewriteRule for the following
www.mysite.com/xyz
or
www.mysite.com/xyz/
==> should go to 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
==> should not be rewritten
Only when there's no file extension, the rewrite rule should be used Thanks!
回答1:
Put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+?)/?$ /page.php?var=$1 [L,QSA]
来源:https://stackoverflow.com/questions/23230032/htaccess-rewriterule-for-directory