正则表达式通过 htaccess 将 url 重定向到新域
我正在尝试通过 htaccess 将具有特定单词的所有 url 重定向到新域。 以下是几个 url 结构:
http://birmingham-printer-repairs.co.uk/brother/printer/repairs/in/abbots-langley/
http://birmingham-printer-repairs.co.uk/brother/printer/repairs/in/accrington/
http://birmingham-printer-repairs.co.uk/sharp/printer/repairs/in/york/
我需要将所有包含 (word Printer/repairs/in) 的 url 重定向到新域
这是我的 WordPress htaccess
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^\/printer\/repairs\/in(.*)$ http://www.newdomain.com/ [R=301,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I am trying to redirect all url with specific word to a new domain via htaccess.
Here are the few url structure:
http://birmingham-printer-repairs.co.uk/brother/printer/repairs/in/abbots-langley/
http://birmingham-printer-repairs.co.uk/brother/printer/repairs/in/accrington/
http://birmingham-printer-repairs.co.uk/sharp/printer/repairs/in/york/
I need all url that contains (word printer/repairs/in) should be redirected to new domain
Here is my htaccess of wordpress
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^\/printer\/repairs\/in(.*)$ http://www.newdomain.com/ [R=301,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下命令:
记住:这应该位于 htaccess 的顶部或其他指令之前
如果两个域(新的和旧的)都指向同一文档根目录,则使用此命令
You can use the following :
Remember : this should be at the top of your htaccess or before other directives
If both domains (new and old) are pointing to the same document root , then use this