Welcome Guest, Not a member yet? Register   Sign In
Extra slash after domain required after removing 'index.php'
#1

[eluser]Zaph[/eluser]
I've been trying to remove the 'index.php' from my Codeigniter site using mod-rewrite. However I end up with this problem:

Original URI: http://mysite.com/index.php/about

Only way to make it work after removing index.php: http://mysite.com//about (note the extra slash)

Removing the extra slash causes Codeigniter to not 'see' the url string after the domain.

I've tried 3 different mod-rewrite methods now and all end up with the same problem - URIs don't work unless you add an extra slash after the domain name.

Thanks!
#2

[eluser]Zaph[/eluser]
Also, this is my current mod_rewrite code I'm using (but I also tried the suggested code on this forum):
Code:
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/system/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]

RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{HTTP_HOST} ^www.domain.co
RewriteRule (.*) http://domain.co/$1 [R=301,L]

</IfModule>
#3

[eluser]Rolly1971[/eluser]
This is my rewrite code in my .htaccess file. nothing special here and i have not had a single issue.

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} www.example.com
RewriteCond $1 !^(index\.php|assets|themes|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !\.(png|jpg|gif|css|js)$
RewriteRule ^(.*)$ /index.php/$1 [L]


#4

[eluser]Zaph[/eluser]
Thanks Rolly, just tried your Rewrite code, but it gave me a different problem.

The homepage loaded without issue, but any other page gave me a 404 (server 404, not Codeigniter 404).


What should the following config.php values be when removing index.php?
$config['base_url'] = 'http://mywebsite.co';
$config['index_page'] = 'index.php';

I've tried messing with them (add/remove trailing slash, remove index.php etc) but it doesn't seem to change anything.
#5

[eluser]Rolly1971[/eluser]
in your config.php it should look something like this:

Code:
$config[‘base_url’] = ‘http://mywebsite.co/’;
$config[‘index_page’] = ‘’;
#6

[eluser]Zaph[/eluser]
Yeah, unfortunately that didn't help.

With config.php as above and your mod_rewrite code, I just get server 404's for anything other than the homepage...
#7

[eluser]Aken[/eluser]
Search Google and this forum for removing index.php, there are hundreds of threads about it.

Start simple, and modify as needed if it doesn't work. Note that sometimes you might need to change the URI protocol option in your config.php to make it work properly.




Theme © iAndrew 2016 - Forum software by © MyBB