问题
I developed one web application in which I used codeigniter, Structure of all the URLs of my web application is as follows:
<?php echo base_url();?>/Admin/Promotions
this type of links are working well in my Localhost but not working on my hosting server (I'm using Godaddy hosting)
But some links which have index.php in URLs are working both on localhost and server too structure of this king of links are
<?php echo base_url();?>index.php/Admin/Pramotions
What shoud I do so that URLs without index.php works well ??
My HTACCESS :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
回答1:
Use this htaccess --
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
then set base_url --
$config['base_url']='http://www.domain_name.com';
then remove index.php in config file --
$config['index_page'] = '';
after that it will work without index.php
回答2:
Open config.php and do following replaces
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
Just replace
$config['uri_protocol'] ="AUTO"
to
$config['uri_protocol'] = "REQUEST_URI"
AND IN HTACCESS FILE put following code
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
回答3:
If none of the answers above worked, perhaps you need to activate mod_rewrite in your httpd.conf:
On terminal:
sudo nano /etc/httpd/conf/httpd.conf
ctrl + w to find for "rewrite"
Uncomment this line:
LoadModule rewrite_module modules/mod_rewrite.so
Save and restart httpd (apache).
回答4:
It is working for me ....htaccess
file is like this...
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
And don't forget to set
$config['base_url']='http://www.domain_name.com';
来源:https://stackoverflow.com/questions/41413728/codeigniter-links-not-working-without-index-php-in-url