htaccess的重写规则的目录重写、规则、目录、htaccess

2023-09-02 09:46:24 作者:今天不打瞌睡

我想使用重写规则以下

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

==>应该去www.mysite.com/page.php?var=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!

推荐答案

将这个code在 DOCUMENT_ROOT /的.htaccess 文件:

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]