简体   繁体   English

完整URL的Apache RewriteMap语法

[英]Apache RewriteMap syntax for full URLs

I have a rewrite map with around 5000 entries like this: 我有大约5000个条目的重写映射,如下所示:

http://www.example.com/some-random-url http://www.example.net/some-random-url http://www.example.com/some-random-url http://www.example.net/some-random-url

For each entry the source domain, eg example.com above, is the same, but the destination domain, example.net above, is a different domain. 对于每个条目,源域(例如,上面的example.com)是相同的,但是目标域(例如,上面的example.net)是不同的域。 The path pattern also changes with each URL (I wish I could post more than 2 links!) 路径模式也会随每个URL发生变化(我希望我可以发布2个以上的链接!)

What I have so far is: 到目前为止,我有:

RewriteEngine On RewriteEngine开

RewriteMap examplemap "txt:/etc/httpd/conf/redirect.txt" RewriteMap示例图“ txt:/etc/httpd/conf/redirect.txt”

RewriteCond ${examplemap:$1} !="" RewriteCond $ {examplemap:$ 1}!=“”

RewriteRule ^/(.*) ${examplemap:$1} [redirect=permanent,last] RewriteRule ^ /(。*)$ {examplemap:$ 1} [redirect = permanent,last]

I cannot seem to get the correct syntax for the RewriteCond and RewriteRule directives and would be grateful for any help, thanks. 我似乎无法为RewriteCond和RewriteRule指令获取正确的语法,感谢您的帮助。

If I understand correctly, you want the key of the rewrite map to be the current URL and then find the matching redirect. 如果我理解正确,则您希望重写映射的键为当前URL,然后找到匹配的重定向。

Then you can use : 然后,您可以使用:

RewriteRule .* ${examplemap:http://%{HTTP_HOST}%{REQUEST_URI}}

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

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