htaccess的重写规则的目录 [英] .htaccess RewriteRule for directory

查看:145
本文介绍了htaccess的重写规则的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用重写规则以下

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]

这篇关于htaccess的重写规则的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆