Regex htaccess来修改URL
我有以下网址:Regex htaccess来修改URL,regex,.htaccess,mod-rewrite,Regex,.htaccess,Mod Rewrite,我有以下网址: http://example.com/at and want to get: http://example.com/at/index.php?at= http://example.com/at/ and want to get: http://example.com/at/index.php?at= http://example.com/at/1asSde and want to get: http://example.com/at/index.php?at=1asSde
http://example.com/at
and want to get:
http://example.com/at/index.php?at=
http://example.com/at/
and want to get:
http://example.com/at/index.php?at=
http://example.com/at/1asSde
and want to get:
http://example.com/at/index.php?at=1asSde
此外,我正在修改位于“at”文件夹中的.htaccess
我一直在努力:
RewriteEngine On
RewriteRule (.*)$ index.php?at=$1 [QSA,L]
但是我以后在运行站点脚本时会出错
为了得到正确的结果,我可以尝试什么
谢谢。试试下面的方法
RewriteEngine On
RewriteRule ^at/(.*)$ at/index.php?at=$1 [QSA,L]
只要
at/index.php
是一个物理位置,就不需要为at
设置规则。我鼓励您在上为创建更好的匹配项。例如,将(.*)
更改为(\w+)
,如果它只能是字母数字。重写规则^at/(.*)/at/index.php?at=$1[QSA,L]
在重写URL之前,您需要确保您试图获取的资源不存在:
RewriteEngine On
RewriteRule ^at/(.*)$ index.php?at=$1 [QSA,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?at=$1 [QSA, L] #didn't test to make sure this line actually works.
您缺少重写条件您是否尝试打印出$\u GET['at']
?我删除了这个问题上的php标记,因为php的使用没有考虑在内。我在$\u GET['at']中得到了我期望的结果。但后来我得到了一些错误,比如:Resource被解释为Image,但使用MIME类型text/html传输。另外,我正在修改/at/.htaccess中的脚本。因此,没有必要处理“at”