Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex htaccess来修改URL_Regex_.htaccess_Mod Rewrite - Fatal编程技术网

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”