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
.htaccess 使用同样具有查询字符串的htaccess在URL末尾添加字符串_.htaccess_Url Redirection_Qsa - Fatal编程技术网

.htaccess 使用同样具有查询字符串的htaccess在URL末尾添加字符串

.htaccess 使用同样具有查询字符串的htaccess在URL末尾添加字符串,.htaccess,url-redirection,qsa,.htaccess,Url Redirection,Qsa,我想换衣服 domain.com/division/index.php?members/maxmusterman.5 到 domain.com/division/index.php?members/maxmusterman.5/#div 也就是说,如果URL包含index.php?成员,那么我会在URL的末尾添加/#div。我试过这个 RewriteEngine On RewriteCond %{REQUEST_URI} index.php? RewriteRule (.*) /%1/%{Q

我想换衣服

domain.com/division/index.php?members/maxmusterman.5

domain.com/division/index.php?members/maxmusterman.5/#div

也就是说,如果URL包含index.php?成员,那么我会在URL的末尾添加/#div。我试过这个

RewriteEngine On
RewriteCond %{REQUEST_URI}  index.php?
RewriteRule (.*)  /%1/%{QUERY_STRING}&123 [L,QSA,R=301]
但它又回来了

domain.com/members/maxmusterman.5和123?members/maxmusterman.5

请注意,在启动参数之前,&123附加在URI之后。我研究了htaccess QSA标志,但找不到在查询字符串末尾添加自定义字符串的方法。我该怎么做呢。这里我使用了&123进行测试,实际需求是添加/div

以重定向

domain.com/division1/index.php?members/maxmusterman.5

domain.com/division/index.php?members/maxmusterman.5/#div
. 您可以使用以下内容:

RewriteEngine on
RewriteCond %{QUERY_STRING} !loop=no
RewriteRule ^division1/index\.php$ %{REQUEST_URI}?%{QUERY_STRING}&loop=no#div [L,R,NE]
我在目标url中添加了一个额外的参数
loop=no
,以防止
无限循环
错误。您无法避免这一点,因为旧url和新url都是相同的,如果删除“重写条件”和“查询参数”,可能会导致重定向循环

NE
(无转义)标志在重定向到片段时非常重要,否则mod rewrite会将
#
转换为其十六进制
%23

解决方案#2


在测试这些重定向之前,请清除浏览器缓存。

您正在使用
℅n
变量,但不设置它<代码>℅n指在
RewriteCond
中匹配的url部分。请参阅starkeen的模式重写手册,我已经很好地解释了我的问题。您标记的dup不能解决我的问题。在我的例子中,问题是在整个url的末尾添加字符串
,其中也包括get参数。这个问题应该打开来回答。问题不是在重定向url的末尾添加sting。你的问题是你没有使用正确的变量和反向引用,也没有遵循手册。@starkeen,这样如果我不知道的话,有人可以修复它。但问题已经结束,你的问题已经重新开始。
RewriteEngine on

RewriteCond %{THE_REQUEST} !.*loop=no [NC]
RewriteCond %{THE_REQUEST} /division1/index\.php\?(.+)\s [NC]
RewriteRule ^ /division1/index.php?%1&loop=no#div [NE,L,R]