【问题标题】:Can't make a 301 redirect in .htaccess file for ASP无法在 .htaccess 文件中为 ASP 进行 301 重定向
【发布时间】:2011-07-10 13:11:53
【问题描述】:

我有一个 WordPress 网站,但在同一个域上是一个旧的 ASPX 网站。这是我用于重定向的 .htaccess 文件:

# BEGIN WordPress 
RewriteEngine On 
RewriteBase / 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
redirect 301 /news/ http://www.doctornestor.co.il/category-news/%D7%9B%D7%9C%D7%9C%D7%99/
redirect 301 /articles/ http://www.doctornestor.co.il/blog/articles-and-newsposts/
redirect 301 /contact.aspx http://doctrnestor.co.il/contact/
redirect 301 /send2friend.aspx http://www.doctornestor.co.il/contact/

那么问题是什么? 当我转到“http://www.doctornestor.co.il/news”时,它会将我发送到正确的 URL 重定向 - http://www.doctornestor.co.il/category-news/%D7%9B%D7%9C%D7%9C%D7%99/,但是当我转到“http://www.doctornestor.co.il/contact.aspx”时,我收到此错误“'/' 应用程序中的服务器错误。”

我猜这是因为我需要做其他事情来重定向 ASPX。我错过了什么?

附:我正在研究 Apache。

【问题讨论】:

  • 在您的重定向之前是否有可能推翻重定向的 404 规则?
  • 是的,wordpress默认的404重定向...

标签: php asp.net apache .htaccess redirect


【解决方案1】:

这只是您问题中的错字还是实际上是您在 .htaccess 中的代码副本?

redirect 301 /contact.aspx http://doctrnestor.co.il/contact/

我认为这应该是 doctornestor

redirect 301 /contact.aspx http://doctornestor.co.il/contact/

【讨论】:

  • 问题是没有执行重定向。这个错字只会影响访问者被重定向到的地方。原来的问题依然存在
  • @James True,但我写的是你的问题吗?
  • 错字仅在问题中。
【解决方案2】:

试试这些规则:

RewriteEngine On 
RewriteBase / 

# redirects
RewriteRule ^news/$ http://www.doctornestor.co.il/category-news/%D7%9B%D7%9C%D7%9C%D7%99/ [QSA,R=301,L]
RewriteRule ^articles/$ http://www.doctornestor.co.il/blog/articles-and-newsposts/ [QSA,R=301,L]
RewriteRule ^contact.aspx$ http://doctornestor.co.il/contact/ [QSA,R=301,L]
RewriteRule ^send2friend.aspx$ http://www.doctornestor.co.il/contact/ [QSA,R=301,L]

# WordPress rules
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L]

请注意:前 2 个重定向与 Redirect 指令完全匹配。这意味着 1 条规则将仅匹配 http://www.domain.com/news/ 而原始重定向也将匹配 http://www.domain.com/news/something => http://www.doctornestor.co.il/category-news/%D7%9B%D7%9C%D7%9C%D7%99/something

如果您想要这种行为,请将这两行替换为:

RewriteRule ^news/(.*)$ http://www.doctornestor.co.il/category-news/%D7%9B%D7%9C%D7%9C%D7%99/$1 [QSA,R=301,L]
RewriteRule ^articles/(.*)$ http://www.doctornestor.co.il/blog/articles-and-newsposts/$1 [QSA,R=301,L]

【讨论】:

  • 它不起作用。问题出在 aspx URL 上。不是前两个。
  • @Asaf 您是否将所有这些规则按此顺序排列......或者您只是将一些规则复制到您现有的 .htaccess 中?请显示您当前 .htaccess 的全部内容。
【解决方案3】:

好的。该问题与我的主机(机架空间)有关 - here

@Adrian、@LazyOne 和 @James - 感谢您的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 2015-08-15
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多