【问题标题】:Codeigniter URLs being redirected or extra part is added to URLCodeigniter URL 被重定向或额外的部分被添加到 URL
【发布时间】:2012-10-30 00:05:11
【问题描述】:

我有一个奇怪的问题。直到昨天一切正常,突然发现这个问题。

网站在这里: http://www.famtripsandinspectionvisits.com/all_trips

如果您访问上面的页面并点击“india-kerala”链接,它应该会将您带到以下页面。

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

但是浏览器会重定向到这个页面: http://www.famtripsandinspectionvisits.com/all_trips/old_trips/india_kerala?/trips/old_trips/india_kerala 这表明添加了以下部分是额外的。 all_trips/old_trips/india_kerala?

我检查了我的 .htaac​​cess 并将其重置为默认值,但它仍然不影响它。我检查了我的 cofnig.php 的基本 url,一切都和以前一样。如果有人能帮忙,我会感谢的。

我的 .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

我的路线.php

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

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

亲切的问候

【问题讨论】:

  • 两个地址现在都返回 404?也许是这个原因?尝试使路径在您的控制器中正常工作以避免 404 并告诉我们它是否正常工作?
  • 您可以发布您的.htaccessroutes.php 文件吗?
  • 我认为问题与重定向有关,或者在某个地方添加了 url 中的额外部分,不确定从哪里添加。
  • 我现在已经添加了 .htaccess 和 router.php 文件。感谢您的帮助
  • 可能最后一个重定向规则是将trips/old_trips/india_kerala重定向到all_trips/old_trips/india_kerala

标签: php codeigniter url


【解决方案1】:

我想你这里需要做的就是告诉 mod_rewrite 你想合并新旧查询字符串,这需要使用 QSA 标志:

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

这是我的 Codeigniter 项目的“标准”基本规则集,其余的我通过自定义路由和偶尔的重定向完成了很多。

仅用问号结束替换(在没有 QSA 标志的情况下)将删除现有的查询字符串并将其替换为新的,我认为这可以解释您所看到的内容。

documentation for mod_rewrite 对此进行了深入探讨:

修改查询字符串

默认情况下,查询字符串原封不动地传递。你可以, 但是,在包含查询的替换字符串中创建 URL 字符串部分。只需在替换字符串中使用问号 表示应将以下文本重新注入 请求参数。当你想删除一个现有的查询字符串时,结束 仅带问号的替换字符串。新旧结合 查询字符串,使用 [QSA] 标志。

【讨论】:

    【解决方案2】:

    我遇到了类似的问题。尝试编辑你 config.php 看起来像这样:

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

    我假设您正在使用 CodeIgniter 的一种 URL 方法,并且您正在(假设)使用 IIS 来托管。我不知道如何删除“?”在 URL 和查询字符串之间添加“?”到您的配置文件应该至少解析链接。

    【讨论】:

    • 是什么让你相信他在使用 IIS?
    • 我假设他正在使用 IIS。我在 IIS 上运行的一个网站也遇到了同样的问题,添加 ? 解决了我的问题。
    猜你喜欢
    • 1970-01-01
    • 2011-10-26
    • 2021-09-10
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    • 2012-04-08
    • 2016-10-18
    • 2012-03-18
    相关资源
    最近更新 更多