简体   繁体   English

重定向的Codeigniter URL或多余的部分已添加到URL

[英]Codeigniter URLs being redirected or extra part is added to URL

I have a strange problem. 我有一个奇怪的问题。 Everything was working fine untill yesterday and suddenly just noticed this problem. 直到昨天一切都很好,突然发现了这个问题。

The webiste is here: http://www.famtripsandinspectionvisits.com/all_trips 网站在这里: http : //www.famtripsandinspectionvisits.com/all_trips

If you visit above page and click on "india-kerala" link, it should take you to the following page. 如果您访问上面的页面并单击“印度喀拉拉邦”链接,它将带您进入下一页。

http://www.famtripsandinspectionvisits.com/trips/old_trips/india_kerala http://www.famtripsandinspectionvisits.com/trips/old_trips/india_kerala

However the browser redirects to this page: http://www.famtripsandinspectionvisits.com/all_trips/old_trips/india_kerala?/trips/old_trips/india_kerala This indicates that the following part was added that is extra. 但是,浏览器将重定向到此页面: http : //www.famtripsandinspectionvisits.com/all_trips/old_trips/india_kerala?/ trips/old_trips/ india_kerala这表明添加了以下内容,这是多余的。 all_trips/old_trips/india_kerala? all_trips / old_trips / india_kerala?

I checked my .htaaccess and reset it to defaultbut it still doesn't affect it. 我检查了.htaac​​cess并将其重置为默认值,但它仍然不影响它。 I checked my cofnig.php for base url and everything is same as before. 我检查了cofnig.php的基本URL,所有内容与以前相同。 If anyone can help, I will appriciate. 如果有人可以帮助,我会提出申请。

my .htaccess file 我的.htaccess文件

# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]  

Redirect 301 /invest.php http://www.famtripsandinspectionvisits.com/investment_opportunity
Redirect 301 /buyers.php http://www.famtripsandinspectionvisits.com/buyers
Redirect 301 /trips.php http://www.famtripsandinspectionvisits.com/all_trips
Redirect 301 /sellers.php http://www.famtripsandinspectionvisits.com/sellers
Redirect 301 /contact.php http://www.famtripsandinspectionvisits.com/contact_us
Redirect 301 /about.php http://www.famtripsandinspectionvisits.com/about_us
Redirect 301 /login.php http://www.famtripsandinspectionvisits.com/login
Redirect 301 /trip-kerala.php http://www.famtripsandinspectionvisits.com/trips/old_trips/india_kerala
Redirect 301 /trip-burundi.php http://www.famtripsandinspectionvisits.com/trips/up_coming_trips/burundi_africa
Redirect 301 /register.php http://www.famtripsandinspectionvisits.com/register
Redirect 301 /trips http://www.famtripsandinspectionvisits.com/all_trips

My routes.php 我的routes.php

$route['default_controller'] = "site";
$route['404_override'] = '';

$route['fam_admin'] = "fam_admin/login";
/* End of file routes.php */
/* Location: ./application/config/routes.php */

Kind regards 亲切的问候

I think what you need to do here is tell mod_rewrite that you want to combine the new and old query strings, which requires the use of the QSA flag: 我认为您在这里需要做的就是告诉mod_rewrite您想组合新旧查询字符串,这需要使用QSA标志:

    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?$1 [QSA,L]

That is my 'standard' base set of rules for my Codeigniter projects, the rest I accomplish much as you have with custom routes and the occasional redirect. 这是我的Codeigniter项目的“标准”基本规则集,其余的我将通过自定义路由和偶尔的重定向来完成您所能完成的工作。

Ending the substitution with just a question mark (in the absence of the QSA flag) will erase the existing query string and replace it with the new one, which I think explains what you're seeing. 仅用问号(在没有QSA标志的情况下)结束替换将删除现有查询字符串,并将其替换为新的查询字符串,我认为这可以解释您所看到的内容。

The documentation for mod_rewrite gets a bit more in depth when it comes to this: 关于mod_rewrite文档在此方面有更深入的介绍:

Modifying the Query String 修改查询字符串

By default, the query string is passed through unchanged. 默认情况下,查询字符串不变。 You can, however, create URLs in the substitution string containing a query string part. 但是,您可以在包含查询字符串部分的替换字符串中创建URL。 Simply use a question mark inside the substitution string to indicate that the following text should be re-injected into the query string. 只需在替换字符串中使用问号来表示应将以下文本重新插入到查询字符串中。 When you want to erase an existing query string, end the substitution string with just a question mark. 当您要删除现有的查询字符串时,只需用问号结束替换字符串。 To combine new and old query strings, use the [QSA] flag. 要组合新旧查询字符串,请使用[QSA]标志。

I had this similar issue. 我有类似的问题。 try editing you config.php to look look like this: 尝试编辑config.php使其看起来像这样:

$config['index_page'] = 'index.php?';

I am assuming you are using one of CodeIgniter's URL methods and you are (assuming) using IIS to host. 我假设您正在使用CodeIgniter的URL方法之一,并且(假设)正在使用IIS进行托管。 I don't know how to remove the '?' 我不知道如何删除“?” between the URL and the query string but adding the '?' URL和查询字符串之间,但添加“?” to your config file should resolve the links at least. 到您的配置文件应至少解析链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM