[英].htaccess redirect only root of a subfolder to another subfolder?
我在“example.com/a”中有一个站点,并且想将 301 仅 url“example.com/a”重定向到“example.com/b”和“example.com/a”中的其他数据不要更改地址。
在“example.com/a”中创建 .htaccess 并尝试使用以下代码:
RewriteEngine on
RewriteRule ^$ http://www.example.com/b [R=301,L]
和
RedirectMatch 301 ^/$ https://example.com/b
及其重定向根目录,但“example.com/a”中的所有其他数据显示 404 错误。
我在“root/a”中有很多照片,只想将“root/a”地址重定向到“root/b”,照片的地址保持不变。
例如“root/a/pic.jpg”地址在重定向前后保持不变,
我怎样才能重定向“example.com/a”而其他旧地址不改变?
如果我理解你,你需要将root/a
重定向到root/b
,同时保持页面、文件的 rest 的位置?
这将做:
# Redirect Root Only
<IfModule mod_rewrite.c>
RewriteEngine On
#Uncheck line below to redirect 'index.php' as well
#Redirect 301 /a/index.php http://example.com/b/
#Redirect root only
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} ^/a/$
Rewriterule ^(.*)$ http://example.com/b/ [L,R=301]
</IfModule>
# END Redirect Root Only
还需要重定向 index.php、index.html 或其他索引页面吗? 取消选中上面代码中的行。 因为%{REQUEST_URI} ^/a/$
排除了所有直接文件路径,包括/a/index.html,index.php,index.py 等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.