【问题标题】:Apache Redirect or RewriteApache 重定向或重写
【发布时间】:2014-11-03 07:15:45
【问题描述】:

我的新网站目前有问题。

实时站点位于名为“live”的子目录中。 因此,我的网址如下所示:www.example.com/live/specials/

我希望我的网址如下所示:www.example.com/specials/

这是我在根目录中的 .htaccess 中的内容:

RewriteEngine On
RewriteRule ^$ live/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ live/$1

提前感谢您的帮助!

【问题讨论】:

  • 您发布的代码有什么问题?它会重定向到错误的位置吗?你有错误吗?
  • 没有错误,工作正常。但我不想在 URL 中看到“live/”。

标签: apache .htaccess mod-rewrite redirect subdirectory


【解决方案1】:

您可以在root .htaccess 中使用此规则:

RewriteEngine On

RewriteRule ^((?!live/).*)$ live/$1 [L]

把它放在/live/.htaccess:

RewriteEngine On
RewriteBase /live/

RewriteCond %{THE_REQUEST} /live/(\S*) [NC]
RewriteRule ^ /%1 [L,R=302,NE]

【讨论】:

  • 感谢您的回复。这行代码和我的代码做的一样。仍然在 URL 中显示“live/”。
  • 您需要输入网址为www.example.com/specials/,规则会在其中添加/live/。
  • 要将www.example.com/live/specials/ 重定向到www.example.com/specials/,请参阅我更新的答案。记得在/live/.htaccess 中添加新规则。
猜你喜欢
  • 1970-01-01
  • 2014-11-27
  • 2017-11-21
  • 2012-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多