CodeIgniter Forums
Mod rewrite problem with Ubuntu - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Mod rewrite problem with Ubuntu (/showthread.php?tid=52694)



Mod rewrite problem with Ubuntu - El Forum - 06-21-2012

[eluser]Mohammed Zayan[/eluser]
I use Ubuntu and enable mod_rewrite in Ubuntu by:
Code:
sudo a2enmod rewrite
and I have restart the server by:
Code:
sudo /etc/init.d/apache2 restart

and I use this code in .htaccess file
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /zayanit/

    #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]
</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>

when I use:
http://localhost/zayanit/site/index
I have this error:
The requested URL /zayanit/site/index was not found on this server.
Apache/2.2.17 (Ubuntu) Server at localhost Port 80
but if I put index.php in url it works.

So what is the problem?!!


Mod rewrite problem with Ubuntu - El Forum - 06-21-2012

[eluser]WanWizard[/eluser]
Your rewrite rule is looking for /index.php, is it in the root of the docroot?


Mod rewrite problem with Ubuntu - El Forum - 06-21-2012

[eluser]Mohammed Zayan[/eluser]
Yes
And when I write
http://localhost/zayanit/index.php/site/index
in the url the page working without any problems


Mod rewrite problem with Ubuntu - El Forum - 06-21-2012

[eluser]WanWizard[/eluser]
Are you using a fastCGI installation? If not, the question mark should not be part of the rewrite rule.

so
Code:
RewriteRule ^(.*)$ /index.php/$1 [L]



Mod rewrite problem with Ubuntu - El Forum - 06-21-2012

[eluser]Mohammed Zayan[/eluser]
I don't know what is fastCGI installation so, I think I don't use it. And I remove the question mark from the rewrite rule.
My code now is
Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /zayanit/

    #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]
</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>

It still doesn't work


Mod rewrite problem with Ubuntu - El Forum - 06-22-2012

[eluser]Mohammed Zayan[/eluser]
What should I do to solve it?


Mod rewrite problem with Ubuntu - El Forum - 06-22-2012

[eluser]CroNiX[/eluser]
Try this by itself. If it doesn't work, try removing the ?. I use this on Ubuntu 10.04 (except I don't need a RewriteBase). The rest of that is unneeded for CI 2+
Code:
RewriteEngine On
RewriteBase /zayanit/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]


Also, I think the problem might be with your if blocks. On my server, the extensions are .so, not .c. If you use the above this will probably confirm that.


Mod rewrite problem with Ubuntu - El Forum - 06-22-2012

[eluser]Mohammed Zayan[/eluser]
I try
Code:
RewriteEngine On
RewriteBase /zayanit/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

And
Code:
RewriteEngine On
RewriteBase /zayanit/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

It doesn't work. I use Ubuntu 11.04