Regex Htaccess重定向与正则表达式匹配的URL
我正在尝试重定向任何符合以下条件的url:Regex Htaccess重定向与正则表达式匹配的URL,regex,.htaccess,mod-rewrite,url-rewriting,rewrite,Regex,.htaccess,Mod Rewrite,Url Rewriting,Rewrite,我正在尝试重定向任何符合以下条件的url: old-domain.com/marketplace/businesses/anything-here/ads/ old-domain.com/marketplace/businesses/anything-here/ads/anyhting-after-this-too old-domain.com/marketplace/businesses/anything-here/ads/anyhting-after-this-too/anyhting-af
old-domain.com/marketplace/businesses/anything-here/ads/
old-domain.com/marketplace/businesses/anything-here/ads/anyhting-after-this-too
old-domain.com/marketplace/businesses/anything-here/ads/anyhting-after-this-too/anyhting-after-this-too/
etc...
到
这就是我的.htaccess
文件的外观
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^marketplace/businesses/([a-z0-9\-_]+)/ads/(.*) http://new-domain.com/deal/ [R=301,L]
</IfModule>
重新启动发动机
重写基/
重写规则^marketplace/businesss/([a-z0-9\-\\\\\\\\\)/ads/(*)http://new-domain.com/deal/ [R=301,L]
我尝试过几种不同的操作系统,包括用([a-Za-z0-9\-\u]+)
和[a-Za-Z-\u0-9]+)
和其他组合替换([a-Za-z0-9\.]+)
,但我似乎无法让它工作
还请注意我在URL中所说的这里的任何内容
,这意味着我希望能够匹配那里的几乎任何内容
任何帮助都将不胜感激
谢谢我想这可能行得通。(不过还没试过)
这会翻译成这个
old-domain.com/marketplace/businesses/anything-here/ads/
old-domain.com/marketplace/businesses/anything-here/ads/anyhting-after-this-too
old-domain.com/marketplace/businesses/anything-here/ads/anyhting-after-this-too/anyhting-after-this-too/
对此
http://new-domain.com/deal/anything-here/ads/
http://new-domain.com/deal/anything-here/ads/anyhting-after-this-too
http://new-domain.com/deal/anything-here/ads/anyhting-after-this-too/anyhting-after-this-too/
或者像这样我想保持零件完整,试试这个
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^marketplace/businesses/([a-zA-Z0-9\-_]+)/ads/([a-zA-Z0-9\-_]+) http://new-domain.com/deal/$1/$2 [NC]
这将被翻译成这个
http://new-domain.com/deal/anything-here/anyhting-after-this-too
但是我不认为另外两个会与regexp匹配。问题是我在
/marketplace/businesss/
上有一个物理目录,其中有一个.htaccess
文件阻止了它的工作
我能够将这个添加到.htaccess
文件中,它就像一个魔咒一样工作
感谢所有看过并尝试过的人。1这不起作用的原因是我需要保持old-domain.com/marketplace/businesss/anywhere-here/完整,因为我有一个php脚本正在转发这些内容。此外,我正在使用301重定向。在我的本地机器上进行的快速测试确认,您的正则表达式应该适用于您尝试执行的操作。我想知道是否有什么不喜欢的反斜杠被用来逃避破折号在第一模式组。你试过[-a-z0-9_uu]或[^/]吗?
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^marketplace/businesses/([a-zA-Z0-9\-_]+)/ads/([a-zA-Z0-9\-_]+) http://new-domain.com/deal/$1/$2 [NC]
http://new-domain.com/deal/anything-here/anyhting-after-this-too