【发布时间】:2013-04-27 17:02:51
【问题描述】:
假设有一个 example.com(在 apache 上工作)并且我们有一个名为“sub”的子目录(example.com/sub)。技术上是否可以配置.htacess 将http://example.com/sub/ 重写为http://example.com/home/ 并将所有流量重定向到它,以便/home 中的任何路径都应该重定向到/sub 中的相同路径,我已经尝试过这个
RewriteEngine On
Options +FollowSymlinks
RewriteRule ^sub/?$ /home/ [R,NC]
Redirect /index.html http://example.com/sub
但最终我得到 404 Not Found。有任何想法吗 ?
附:即使我收到 1 个答案,我之前的问题也已关闭:
RewriteRule /sub/$ /home/$1 [NC,L,R=301]
RewriteRule /index.html http://example.com/sub [R]
这对我不起作用(401 禁止)。
【问题讨论】:
-
请澄清您的问题,以便您向我们举例说明用户将在浏览器地址栏中看到的内容,以及您是否希望他们重定向到不同的地址(这会改变他们在地址栏中看到的内容) ) 或者您想要静默重写(指向实际文件,但不会更改用户浏览器在地址栏中显示的内容)。目前尚不清楚您要达到的目标。
-
好吧,我想澄清一下:我想让最终用户在浏览器中看到 example.com/home 而不是 example.com/sub 并且我想从 example.com 重定向到 example.com/home 。希望现在你能理解我。
标签: apache mod-rewrite redirect url-rewriting