无法在ASP的.htaccess文件中进行301重定向

时间:2011-07-10 13:11:53

标签: php asp.net apache .htaccess redirect

我在同一个域上有一个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”时,它会向我发送正确的网址重定向 - http://www.doctornestor.co.il/category-news/%D7%9B%D7%9C%D7%9C%D7%99/,但当我转到“http://www.doctornestor.co.il/contact.aspx”时,我收到此错误“服务器错误在'/'应用程序“。

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

P.S。我正在研究Apache。

3 个答案:

答案 0 :(得分:0)

这只是你问题中的拼写错误,还是.htaccess中代码的副本?

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

我认为这应该是 doctornestor

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

答案 1 :(得分:0)

请尝试以下规则:

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]

请注意:Redirect指令相比,前2个重定向完全匹配。这意味着1条规则仅匹配http://www.domain.com/news/,而原始重定向也匹配http://www.domain.com/news/something =&gt; 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]

答案 2 :(得分:0)

o.k。该问题与我的主机(rackspace)相关 - here

@Adrian,@ LazyOne&amp; @James - 谢谢你的帮助。