【问题标题】:Redirect 301 With Matching Parameter .htaccess使用匹配参数 .htaccess 重定向 301
【发布时间】:2014-07-21 11:57:05
【问题描述】:

我正在将网站从旧的传统 (m.) url 重定向到响应式设计 url。

这是我的 url 和 htaccess 示例。

Old traditional URL => New Responsive design URL 

m.mydomain.com => mydomain.com
m.mydomain.com/mobiles.html => mydomain.com/mobiles
m.mydomain.com/mobiles/android-phones.html => mydomain.com/mobiles/android-phones-price.html
m.mydomain.com/mobiles/android/samsung-phones.html => mydomain.com/mobiles/samsung/android-phones.html

.htaccess

RedirectMatch 301  m.mydomain.com/mobiles/android/(.*)-phones.html mydomain.com/mobiles/$1/android-phones.html

但我收到 Internal Server Error (500) 。 如何解决此问题。

【问题讨论】:

  • 当您收到内部服务器错误时,第 1 步是:检查 Apache 错误日志。
  • 我对 RedirectMatch 不是很熟悉,但是您可以尝试以下方法:将 RedirectMatch 中的 M 大写。将RedirectMatch 的第三个参数设为实际网址。那就是:包括一个协议。
  • 我改成了“RedirectMatch”,即使遇到同样的错误

标签: .htaccess redirect mod-alias


【解决方案1】:

您无法使用RedirectMatch 指令匹配主机名。 请改用mod_rewrite 规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^m\.mydomain\.com$ [NC]
RewriteRule ^$ http://mydomain.com/ [L,R=301]

RewriteCond %{HTTP_HOST} ^m\.mydomain\.com$ [NC]
RewriteRule ^mobiles\.html$ http://mydomain.com/mobiles [L,NC,R=301]

RewriteCond %{HTTP_HOST} ^m\.mydomain\.com$ [NC]
RewriteRule ^mobiles/android-phones\.html$ http://mydomain.com/mobiles/android-phones-price.html [L,NC,R=301]

RewriteCond %{HTTP_HOST} ^m\.mydomain\.com$ [NC]
RewriteRule ^mobiles/android/samsung-phones\.html$ http://mydomain.com/mobiles/samsung/android-phones.html [L,NC,R=301]

【讨论】:

  • 很好的规则系列,+1。希望它适用于拉加。 :)
猜你喜欢
  • 2016-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-11
  • 2017-09-20
  • 2015-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多