【问题标题】:htaccess how to redirect subdirectory to external URLhtaccess如何将子目录重定向到外部URL
【发布时间】:2012-04-19 12:29:43
【问题描述】:

我试过了:

//301 Redirect Old File
Redirect 301 www.mydomain.com/subdirectory http://newurl.com

但这让我进入了不存在的 newurl.com/subdirectory。

【问题讨论】:

  • 我之前问过这个问题,并在网上搜索了答案,但一无所获。我假设这不能用 htaccess 完成。猜猜 PHP 将不得不这样做。

标签: regex apache .htaccess mod-rewrite redirect


【解决方案1】:

启用 mod_rewrite 和 .htaccess 然后将此代码添加到 DOCUMENT_ROOT 下的 .htaccess 中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^subdirectory/?$ http://newurl.com [L,R=301,NC]

【讨论】:

  • 这会放在子目录中的 htaccess 文件中,对吗?
  • 在 DOCUMENT_ROOT 下的主 .htaccess 中没有
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-12-08
  • 2013-09-11
  • 2020-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多