htaccess重定向追加查询字符串

时间:2012-06-25 20:38:50

标签: php apache .htaccess codeigniter

如果我去rocketroofing.us/rocket,它会将我重定向到rocketroofing.us/rochester-minnesota-roofing-contractor?/rocket。为什么它附加了查询字符串以及如何修复它?

htaccess的:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

    # redirect from the old controller names to the new ones to try and help our SEO.
    #redirect 301 / http://rocketroofing.us/rochester-minnesota-roofing-contractor
    redirect 301 /rocket http://rocketroofing.us/rochester-minnesota-roofing-contractor
    redirect 301 /about http://rocketroofing.us/about-rochester-rocket-roofing
    redirect 301 /faq http://rocketroofing.us/frequently-asked-questions
    redirect 301 /contact http://rocketroofing.us/contact-minnesota-roofing-company

</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

路线:

$route['default_controller'] = "rocket";
$route['404_override'] = '';
// used to try and increase my SEO
$route['rochester-minnesota-roofing-contractor'] = 'rocket';
$route['about-rochester-rocket-roofing'] = 'about';
$route['frequently-asked-questions'] = 'faq';
$route['contact-minnesota-roofing-company'] = 'contact';

1 个答案:

答案 0 :(得分:2)

您在此处请求此行为:

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

$1是对正则表达式中与.*匹配的任何内容的反向引用。

除非您像这样定义自己的查询字符串,否则将使用该查询字符串:

redirect 301 /rocket http://rocketroofing.us/rochester-minnesota-roofing-contractor?

请注意尾随问号。记录here

  

默认情况下,查询字符串不会更改。您可以,   但是,在包含查询的替换字符串中创建URL   字符串部分。只需在替换字符串中使用问号   表示应将以下文本重新注入   请求参数。如果要删除现有查询字符串,请结束   替换字符串只有一个问号。结合新旧   查询字符串,使用[QSA]标志。