.htaccess RewriteRule for directory

余生颓废 提交于 2019-12-24 05:34:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!