繁体   English   中英

Apache htaccess RewriteRule不起作用

[英]Apache htaccess RewriteRule not working

由于某些原因,我确实无法使.htaccess RewriteRule正常工作。 我尝试了很多事情并进行了谷歌搜索,但是失败了。 一个可能的原因可能是我有一个很旧的Apache版本(但这是我无法控制的)。 不确定如何获取版本,但是phpinfo()向我显示“ Apache API版本20051115”。 它必须至少在台式机,Blackberry和iPad上运行。

我要将其重写: http : //subdomain.domain.com/folder1/? id= 1234更改为以下内容: http : //othersubdomain.domain.com/? id= 1234其中id可以是任何数字(我是可以重写任何参数,也可以重定向到/ folder1 /?id = 1234,这很重要,重要的是子域和参数仍然存在的事实。 重要的是我(在任何设备上)都没有弹出验证窗口。

我尝试了以下方法:

AuthUserFile /home/user/path/to/.htpasswd
AuthGroupFile /dev/null
AuthName "This site requires a valid username and password"
AuthType Basic

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^folder1.*$ http://othersubdomain.domain.com%{REQUEST_URI}? [redirect=301,last]

<limit GET POST>
require valid-user
</limit>

现在似乎唯一正确地重定向到我的机器上的东西是subdomain.domain.com/folder1/(没有最后一个/它不起作用,或者如果我在末尾添加参数,即... / folder1 /? id = 1234也不起作用)。

我进一步尝试了以下方法:

AuthUserFile /home/user/path/to/.htpasswd
AuthGroupFile /dev/null
AuthName "This site requires a valid username and password"
AuthType Basic

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/folder1
RewriteRule .* http://othersubdomain.domain.com/?%{QUERY_STRING} [redirect=301,last]

<limit GET POST>
require valid-user
</limit>

这种重定向似乎有效,但是只有在我提供了正确的身份验证用户/密码之后,这才是我想要避免的。

提示不只是受欢迎...

我认为这应该工作(没有任何RewriteCond):

RewriteRule ^folder1(.*)$ http://othersubdomain.domain.com$1 [L,QSA,R=301]

QSA标志告诉保持查询参数。 $ 1被替换为()的内容。

PS据我所知,您只能在RewriteCond中使用%{...}变量。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM