【问题标题】:Redirect a folder to a subfolder将文件夹重定向到子文件夹
【发布时间】:2021-09-08 18:49:14
【问题描述】:

我正在尝试重定向这些类型的 URL:

https://www.example.com/my-account/VARIABLE-FOLDER/

https://www.example.com/my-account/VARIABLE-FOLDER/home/

我不太熟悉使用 htaccess 进行复杂的重定向,有人可以帮我吗?

我试过了,但没有结果:

RewriteRule ^my-account/(.*)$ https://www.example.com/my-account/(.*)$/home/ [R=301,NC,L]

目前有我所有的 htaccess 规则:

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

提前致谢


更新 #1,我刚试过这个:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(mon-compte/.*)/?$ https://vide.ecoles-libres.fr/$1/home/ [R=301,NC,L]
</IfModule>

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

我现在被这样重定向: https://example.com/my-account/VARIABLE-FOLDER/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home/home//home/

【问题讨论】:

  • 除了显示的之外,如果您还有其他 htaccess 规则,请告诉我们吗?
  • 我刚刚做到了 :)
  • 好的,感谢添加,我现在添加了答案。

标签: .htaccess redirect mod-rewrite url-rewriting friendly-url


【解决方案1】:

根据您显示的尝试,请尝试以下操作。请在测试您的 URL 之前清除您的浏览器缓存。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)/?$ https://%{HTTP_HOST}/$1 [R=301,NE,L]

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteRule ^index\.php$ - [L]
##Add an additional condition to check about URI here.
RewriteCond %{REQUEST_URI} !/home [NC]
RewriteRule ^(my-account/.*)/?$ https://www.example.com/$1/home/ [R=301,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

【讨论】:

  • 我刚试了一下,可惜好像没用,我清除了缓存,甚至尝试使用其他带有私人导航的浏览器。
  • @JonathanCollery,请告诉我您要访问的网址是什么?你遇到了什么错误?
  • 我仍然点击:example.com/my-account/VARIABLE-FOLDER 而不是:example.com/my-account/VARIABLE-FOLDER/home 而且我没有收到任何错误。
  • 精度:我的 htaccess 中也有这段代码(在它的顶部):&lt;IfModule mod_rewrite.c&gt; RewriteEngine on RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"' RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] &lt;/IfModule&gt;
  • 完美运行!我只是希望 WordPress 不会再次删除您的请求。在所有情况下,非常感谢你的责任:)!
猜你喜欢
  • 2018-09-30
  • 2017-12-05
  • 2016-05-08
  • 2015-05-27
  • 1970-01-01
  • 2017-03-09
  • 2015-10-06
  • 2012-10-23
  • 1970-01-01
相关资源
最近更新 更多