【问题标题】:Cannot 301 redirect this page to a specific page无法 301 将此页面重定向到特定页面
【发布时间】:2013-07-21 18:06:55
【问题描述】:

我想要这个页面:

http://mystore.com/Login.aspx?ReturnUrl=%2fPages%2fHome%2fUser%2fWish-list.aspx

http://mystore.com/en/ukeurope/home

所以,我试着写一个这样的 301 重定向规则:

RewriteRule ^Login.aspx$ en/ukeurope/home? [R=301,L]

但是当我想尝试这种重定向时。 它给了我 404 not Found。

附:我不想要另一个是

mystore.com/Page/Login.aspx

被这个 301 重定向规则重定向

【问题讨论】:

  • 如果你想重定向到mystore.com/home,为什么你的规则中有en/ukeurope
  • @RaviThapliyal 已编辑。对不起
  • 当你直接转到:http://mystore.com/en/ukeurope/home 是否可以正常工作?
  • @anubhava 它工作正常。

标签: .htaccess mod-rewrite http-status-code-301


【解决方案1】:

通过httpd.conf启用mod_rewrite和.htaccess,然后把这段代码放到你.htaccessDOCUMENT_ROOT目录下:

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+Login\.aspx?ReturnUrl=\%2fPages\%2fHome\%2fUser\%2fWish-list\.aspx [NC]
RewriteRule ^ /en/ukeurope/home? [R=302,L]

【讨论】:

  • +1 我不知道 THE_REQUEST(所以可能会使用 URI 和查询字符串检查)。但是,只是为了学习,/+Login 中的+ 是必需的还是您的意思是?
  • /+Login 表示/Login///Login,因为理论上域名后面也可以有多个/
猜你喜欢
  • 2017-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-11
  • 1970-01-01
  • 2012-12-21
  • 2013-12-14
  • 1970-01-01
相关资源
最近更新 更多