【问题标题】:extra slash after removing index.php using htaccess使用 htaccess 删除 index.php 后的额外斜线
【发布时间】:2016-10-04 19:38:05
【问题描述】:

我在域名后多了一个斜杠,例如http://localhost/folder//project/list_all

以下是用于从 url 中删除 index.php 的 htaccess 代码 我正在使用 codeigniter

RewriteEngine On

RewriteRule ^index.php/(.*)$ /$1 [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]

就是在上面的代码后面多了一个斜杠。

如何解决?

//full code

controller/project

public function list_all() {
  //code....
)
//----------------------------

routes.php

$route['default_controller'] = 'home';
//--------------------------------

config.php
$config['base_url'] = 'http://localhost:8080/folder';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
//--------------------------------------------------

//controller home.php 
public function home() {
   //call model load data
   //call view
}

【问题讨论】:

  • RewriteRule ^index.php/(.*)$ 只会影响以 /index.php/ 开头的 URL,您的 .htaccess 位于哪里?

标签: php .htaccess codeigniter


【解决方案1】:

您的代码似乎是一些东西两次,试试这个:

<IfModule mod_rewrite.c>

    RewriteEngine on

    # Send request via index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

您的 htaccess 必须位于您的索引文件所在的位置

【讨论】:

  • 感谢您的回复,我已经输入了您的代码.. 它仍然给出了双斜杠
  • 我应该用什么来修复它?
  • 那么你的问题出在其他地方。您的 $config[] 中有对“文件夹”的引用吗?如果您可以发布一些代码,我可以看到您如何组装这个url,也许我可以找到一个解决方案。
  • 我还假设您在配置中将其设置为空值 `$config['index_page'] = ' ' ;
  • 我们在这里做了很多猜测,这个讨论变成了扩展。我真的需要看看你的代码来解决这个问题。如果您在此处发布所有相关代码,我愿意为您提供帮助。
猜你喜欢
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
  • 2021-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-06
  • 2012-08-16
相关资源
最近更新 更多