简体   繁体   English

apache rewritemap使用txt文件-匹配失败

[英]apache rewritemap using txt file - match fail

I am trying to establish a rewritemap using a simple txt file for a special project that will ultimately contain about 150 redirects. 我正在尝试使用一个简单的txt文件为一个特殊项目建立一个rewritemap,该项目最终将包含大约150个重定向。

I've read through the other posts here and tried to apply alternate mods, but I just can't make a single redirect from this actually work as expected :-/ 我已经阅读了这里的其他文章,并尝试应用替代的mod,但是我无法像预期的那样从此实际工作中进行单个重定向:-/

To confirm my setup: 确认我的设置:

I am using an include .conf to update my httpd.conf for the proper Virtual host. 我正在使用一个include .conf来为适当的虚拟主机更新我的httpd.conf。 Upon running /scripts/rebuildhttpdconf (and 'service httpd restart') it is applied without error and the appropriate Include Path reference within httpd.conf becomes uncommented, which tells me it is finding the include file as expected. 在运行/ scripts / rebuildhttpdconf(和“ service httpd restart”)后,它将正确应用,并且httpd.conf中的适当“包含路径”引用将变为未注释状态,这表明我正在按预期方式找到包含文件。 The Include file is called 'redirecttest2.conf' and contains: 包含文件称为“ redirecttest2.conf”,其中包含:

RewriteMap redirect2 txt:/home/example/public_html/redirecttest/redirect2.txt

At the location referenced above, I have the file 'redirect2.txt', which for testing purposes contains: 在上面引用的位置,我有文件“ redirect2.txt”,出于测试目的,该文件包含:

maintenance.html    http://www.example.com/maintenance2.html
maintenance1.html   http://www.example.com/maintenance2.html

So my expectation would be that when entering 'example.com/maintenance.html' it would then be redirected to maintenance2.html, etc. 所以我的期望是,当输入“ example.com/maintenance.html”时,它将被重定向到maintenance2.html等。

In the .htaccess file at the root of the effected domain, I currently have the following: 在受影响域根目录下的.htaccess文件中,我当前具有以下内容:

RewriteEngine on
RewriteCond %{REQUEST_URI} !(\.(js|css|less|png|php|swf|flv|jpg))$
RewriteCond {redirect2:$1} !=""
RewriteRule ^/(.*) ${redirect2:$1} [R=301,L]

However, this does not currently have any effect. 但是,这目前没有任何效果。 Entering example.com/maintenance.html or maintenance1.html does not perform any redirection - with or without the first two conditionals commented out. 输入example.com/maintenance.html或maintenance1.html不会执行任何重定向-不管是否注释了前两个条件。

I have tried numerous variations, and at times been able to break it altogether (rewrite loop error, whitescreen, or even cases in which the redirect works but instead of going to maintenance2.html, it appends /home/example/public_html to the url - ???) - but at no point can I get the example above to redirect as expected. 我尝试了多种变体,有时甚至可以完全打破它(重写循环错误,白屏,甚至是重定向有效的情况,但不使用maintenance2.html,而是将/ home / example / public_html附加到url -???)-但我无法获得上面的示例以按预期方式进行重定向。

I tried getting assistance from the host of the VPS, but they do not provide support for such modifications. 我尝试从VPS的主机获得帮助,但它们不提供对此类修改的支持。

I am hoping someone could look at the above and maybe see something glaring that I am missing? 我希望有人可以看一下上面的内容,也许会看到我所缺少的明显的东西? ANY thoughts appreciate... 任何想法都感激...

I was finally able to resolve the issues with my RewriteMap. 我终于可以使用RewriteMap解决问题。

In the .htaccess file at the root of the impacted domain, I am now using the following: 在受影响域根目录的.htaccess文件中,我现在使用以下内容:

RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.(js|css|less|png|php|swf|flv|jpg))$
RewriteCond ${redirect2:$1} >"" [NC]
RewriteRule ^(.*) ${redirect2:$1} [R=301,L]

This now appears to work - at least for basic url's. 现在似乎可以正常工作-至少对于基本url而言。

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

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