2010-05-08 68 views
0

最近我重构现有的CodeIgniter应用程序使用URL段,而不是查询字符串,和我使用的是重写规则htaccess的重写东西的index.php:通过.htaccess请求index.php时发送404?

RewriteRule ^(.*)$ /index.php/$1 [L] 

我的问题,现在是,很多这个网站的网页都是通过谷歌索引并链接到index.php。由于我改变了使用网址段,我不再关心这些谷歌结果了,我想发送一个404(不需要使用301永久移动,已经有足够的变化,它只需要重新抓取一切)。

为了说明问题:如何将请求重定向到/index.php?wd到404页面?我正在考虑重写一个不存在的文件,这会导致apache发送一个404。这是一个可接受的解决方案吗?那个样子的重写将如何?

编辑:
目前,现有的谷歌的结果只会导致以下错误:

An Error Was Encountered

The URI you submitted has disallowed characters.

我想是这样的:

RewriteRule ^index\.php?(.*)$ /no-exist.html [R=404,L] 

却引起了内部服务器错误。

EDIT2:

笨正在发送“400”的错误,这将足以让我的网页从谷歌删除?

回答

2

重写规则的R[=code]标志允许code仅从范围300-400。

不要使用重定向R标志 - 只是尝试重写一个平平无奇页:

修订: 两个重定向并列对方 - 使用RewriteCond s到躲避干扰。

完全的.htaccess

RewriteEngine on 

RewriteCond %{REQUEST_URI} ^/index.php.* 
RewriteCond %{QUERY_STRING} !^$ 
RewriteRule ^(.*)$ /no-exist.html [L] 

RewriteCond %{REQUEST_URI} !^/index.php.* 
RewriteCond %{REQUEST_URI} !^/no-exist.html.* 
RewriteRule ^(.*)$ /index.php/$1 [L] 

注意/no-exist.html actualy不存在。假设它会帮助你。

+0

不行的,还是内部服务器错误。 – 2010-05-08 21:04:45

+0

我发现问题:slash/in'/ no-exists.html'语句不应该在这里(只是'no-exists.html')。我已经解决了我的答案。测试 - 它的工作。 – 2010-05-09 07:00:45

+0

斜杠对我的其他重写工作正常...不用说,这仍然导致内部服务器错误。也许2个重写文件不会很好地结合在一起。 – 2010-05-09 09:39:08

1

有一个特殊的HTTP状态代码410 GONE告诉世界,除去资源: 所请求的资源 的index.php 不再可用此服务器上,并没有转发地址。请删除对此资源的所有引用。

要重写规则发送该代码的使用[G|gone]标志:

RewriteEngine on 

RewriteCond %{REQUEST_URI} ^/index.php.* 
RewriteCond %{QUERY_STRING} !^$ 
RewriteRule ^(.*)$/[G,L] 

RewriteCond %{REQUEST_URI} !^/index.php.* 
RewriteRule ^(.*)$ /index.php/$1 [L]