正则表达式通过 htaccess 将 url 重定向到新域
Regex redirect url to new domain through htaccess
我正在尝试通过 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/
我需要将包含(单词 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
您可以使用以下内容:
记住:这应该在你的 htaccess 的顶部或其他指令之前
RewriteEngine On
RewriteRule printer/repairs/in https://example.com [L,R]
如果两个域(新旧)都指向同一个文档根目录,则使用此
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
RewriteRule printer/repairs/in https://example.com [L,R]
我正在尝试通过 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/
我需要将包含(单词 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
您可以使用以下内容:
记住:这应该在你的 htaccess 的顶部或其他指令之前
RewriteEngine On
RewriteRule printer/repairs/in https://example.com [L,R]
如果两个域(新旧)都指向同一个文档根目录,则使用此
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$
RewriteRule printer/repairs/in https://example.com [L,R]