简体   繁体   English

无法从codeigniter网站URL删除index.php?

[英]Can't remove index.php from codeigniter site URL?

I've read guides on its removal and they tell me to add this to a .htaccess in my htdocs root directory: 我已经阅读了有关删除它的指南,他们告诉我将其添加到我的htdocs根目录中的.htaccess中:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

However my websites directory is like so: htdocs\\mywebsite\\ 但是我的网站目录是这样的:htdocs \\ mywebsite \\

I've tried adding the htaccess file in both htdocs and mywebsite but without result. 我尝试在htdocs和mywebsite中都添加htaccess文件,但没有结果。 I've also tried modifying the last line to look like 我也尝试将最后一行修改为

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

In both htdocs and mywebsite directory. 在htdocs和mywebsite目录中。 But I have no idea what is correct .htaccess syntax or how it works, so I didn't really expect it to work. 但是我不知道什么是正确的.htaccess语法或它如何工作,因此我并不真正希望它能工作。

I've also tried modifying the .htaccess file everywhere else in the codeigniter dir tree. 我也尝试在codeigniter目录树中的其他任何地方修改.htaccess文件。

Have you seen this one? 你看过这个吗? How to remove "index.php" in codeigniter's path 如何在codeigniter的路径中删除“ index.php”

Did you change the index_path variable in the config file? 您是否在配置文件中更改了index_path变量? That's application/config/config.php, line 29 in version 2.1.3 那是application / config / config.php,版本2.1.3中的第29行

There needs to be a htaccess file in both the root and website directory. 在根目录和网站目录中都需要有一个htaccess文件。 They need to both contain the same content except the file in root needs to have the path to the index updated to include your website dir. 它们都需要包含相同的内容,只是根目录中的文件需要更新索引的路径以包含您的网站目录。

Root dir: 根目录:

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ yourwebsite/index.php/$1 [QSA,L]

Web dir: 网站目录:

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]

Make sure you have this in your virtual host entry: 确保您的虚拟主机条目中包含以下内容:

    <Directory "/path...to directory">
        Order allow,deny
        Allow from all
        Allowoverride all
    </Directory>

    <IfModule mod_rewrite.c>
        RewriteEngine on
    </IfModule>

You don't need to modify any .htaccess files except in the root. 除了根目录外,您不需要修改任何.htaccess文件。 And as mentioned above, make sure you have things set up right in the config.php file. 并且如上所述,请确保已在config.php文件中正确设置了所有内容。

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

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