CodeIgniter Forums

Full Version: The all famous mod_rewrite issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]selman555[/eluser]
All famous because so many people are having problems figuring it out! Big Grin

Hi by the way.

Could someone please explain to me what I need to do in the following situation:
I developed my website in CI on localhost via xampp. When the site was finished, I copied the site to my webdomain and got it right up to the point that mod_rewrite worked online.
I lost my offline project, so now I recopied the website from my domain to my xampp (which was also reinstalled -> new pc). I already added the .htaccess file:
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

php_flag short_open_tag off
php_flag magic_quotes_gpc Off
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>
Both rewriteBase / and http://localhost/Tong-Il/ didn't work.

I also uncommented LoadModule rewrite_module modules/mod_rewrite.so in httpd.conf and replaced all AllowOverride None to All.

Also:
Code:
$config['base_url'] = '';
$config['index_page] = '';
have been set in application/config/config.php.

When I load the page in xampp via localhost/Tong-Il/, I get the homepage, but when clicking any link, it says 500 internal server error:
Code:
Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.
Error 500
localhost
Apache/2.4.2 (Win32) OpenSSL/1.0.1c PHP/5.4.4

The site can be found online at www.tong-il-neeroeteren.be
Help!?

El Forum

[eluser]Clooner[/eluser]
What do the log files say?

El Forum

[eluser]selman555[/eluser]
[quote author="Jeroen Schaftenaar" date="1342549812"]What do the log files say? [/quote]
Does ci save these errors with a description? I don't know, because my application/logs folder is empty. I don't have error handling for this kind of error as I don't know where this error is generated.

El Forum

[eluser]Clooner[/eluser]
Mod_rewrite is a web server issue, try looking at those...

El Forum

[eluser]selman555[/eluser]
[quote author="Jeroen Schaftenaar" date="1342550403"]Mod_rewrite is a web server issue, try looking at those...[/quote]
Not sure what I should look at.
When I started my project the first time, I got it working on xampp and on the domain.
Now I don't remember what settings I have to change in order for mod_rewrite to work with xampp.

El Forum

[eluser]Clooner[/eluser]
[quote author="selman555" date="1342550731"][quote author="Jeroen Schaftenaar" date="1342550403"]Mod_rewrite is a web server issue, try looking at those...[/quote]
Not sure what I should look at.
When I started my project the first time, I got it working on xampp and on the domain.
Now I don't remember what settings I have to change in order for mod_rewrite to work with xampp.[/quote]

In the apache log files, there it will say exactly why it gives the 500 error!

El Forum

[eluser]selman555[/eluser]
[quote author="Jeroen Schaftenaar" date="1342557797"][quote author="selman555" date="1342550731"][quote author="Jeroen Schaftenaar" date="1342550403"]Mod_rewrite is a web server issue, try looking at those...[/quote]
Not sure what I should look at.
When I started my project the first time, I got it working on xampp and on the domain.
Now I don't remember what settings I have to change in order for mod_rewrite to work with xampp.[/quote]

In the apache log files, there it will say exactly why it gives the 500 error![/quote]
I checked the apache logs, but there's no reference to the 500 errors.
Recently, I found out that I can access all of my pages using the index.php suffix. Pretty stupid of me not to check that first, so now the only problem left is mod_rewrite.
the index.php should be rewritten, but now I always get the object not found error.
The only page that does work without the index.php suffex in my homepage or indexpage...

Any suggestions on that?

El Forum

[eluser]Clooner[/eluser]
[quote author="selman555" date="1342559935"][quote author="Jeroen Schaftenaar" date="1342557797"][quote author="selman555" date="1342550731"][quote author="Jeroen Schaftenaar" date="1342550403"]Mod_rewrite is a web server issue, try looking at those...[/quote]
Not sure what I should look at.
When I started my project the first time, I got it working on xampp and on the domain.
Now I don't remember what settings I have to change in order for mod_rewrite to work with xampp.[/quote]

In the apache log files, there it will say exactly why it gives the 500 error![/quote]
I checked the apache logs, but there's no reference to the 500 errors.
Recently, I found out that I can access all of my pages using the index.php suffix. Pretty stupid of me not to check that first, so now the only problem left is mod_rewrite.
the index.php should be rewritten, but now I always get the object not found error.
The only page that does work without the index.php suffex in my homepage or indexpage...

Any suggestions on that?[/quote]

If you get a 404 it could be that your mod_rewrite is not enabled, as you set it up to display a 404 when mod_rewrite is not enabled. Also try using it without the question mark in this
Code:
RewriteRule ^(.*)$ index.php?/$1 [L]
Code:
RewriteRule ^(.*)$ index.php/$1 [L]
. Again what really is happening should be in the apache log files.

El Forum

[eluser]selman555[/eluser]
[quote author="Jeroen Schaftenaar" date="1342560252"]
If you get a 404 it could be that your mod_rewrite is not enabled, as you set it up to display a 404 when mod_rewrite is not enabled. Also try using it without the question mark in this
Code:
RewriteRule ^(.*)$ index.php?/$1 [L]
Code:
RewriteRule ^(.*)$ index.php/$1 [L]
. Again what really is happening should be in the apache log files.[/quote]
Not enabled? If I recall correctly, I should just uncomment a line and replace allowoverride none with allowoverride all in httpd.conf so that xampp settings can be overwritten with .htaccess files.
The .htaccess file I posted here is the one I used on my old pc, where it worked just fine.

I also tried your suggestion and deleted the "?", but i'm still getting the 404 error.
I think i'm going to give up!

El Forum

[eluser]Aken[/eluser]
Your RewriteBase is probably wrong. It doesn't use URLs, it uses paths.

Try a simple .htaccess:

Code:
RewriteEngine On
RewriteBase /Tong-Il/

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

You might need to adjust $config['uri_protocol'] if the .htaccess alone doesn't work. Might also need to add the ? into the RewriteRule - it all depends on your setup. Try stuff, see what works.
Pages: 1 2