Welcome Guest, Not a member yet? Register   Sign In
Can't seem to remove "index.php" from URLS on my new server? It's a server configuration issue that I can't figure out!
#1

[eluser]skcin7[/eluser]
Help! I recently moved to a new server, and mod_rewrite in my .htaccess file doesn't seem to be properly rewriting the "index.php" to remove it from my URLs. I didn't change any of my files from my existing server, so this tells me that it's some kind of server configuration issue, which makes sense since I just switched servers. Fortunately, I have full access to the server, so I can change anything I need to. If you can help me figure out this problem, it would be most appreciated.

This is what my .htaccess file looks like.

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

This is what my vhost.conf apache file looks like (I think the problem might be in here)

Code:
NameVirtualHost *:80

<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName nmwebstudio.com
        ServerAlias www.nmwebstudio.com
        DocumentRoot /srv/www/nmwebstudio.com/public_html/
        ErrorLog /srv/www/nmwebstudio.com/logs/error.log
        CustomLog /srv/www/nmwebstudio.com/logs/access.log combined
</VirtualHost>

I don't think it has to do with my general apache or PHP configuration files so I'm not going to copy/paste them here. They're also much MUCH longer. If you need to see my phpinfo, you can find it here: http://www.nmwebstudio.com/phpinfo.php

Oh by the way, the site is here: http://www.nmwebstudio.com/ If you click on the "About" tab at the top, you will see what I'm talking about, but you can manually add "index.php" into the URL and it will work fine.

Thanks in advance for any help you may provide. Smile
#2

[eluser]CroNiX[/eluser]
Are you using 2.1? If so, you can safely remove this:
Code:
#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]
Those directories have their own htaccess preventing direct access.

You might try removing the ? in the last line that is like
Code:
RewriteRule ^(.*)$ index.php?/$1 [L]
And see if that helps.

The problem could be in the apache conf as well. If they don't allow you to override default values, it won't use the rewrite.

Here are some directives that have worked for me:
Code:
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
AllowOverride All is important

It could also be that your if block
Code:
<IfModule mod_rewrite.c>
needs to be
Code:
<IfModule mod_rewrite.so>
depending on the extension your server is using. Hope one of those works for you.
#3

[eluser]skcin7[/eluser]
Thanks for your reply. I am using CodeIgniter 2.1 so I was able to remove all that junk from my .htaccess - thanks. It works perfectly on my personal XAMPP stack and it now looks like this:

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

It definitely needs to be <IfModule mod_rewrite.c>. If I change it to mod_rewrite.so, it doesn't work at all.

I think the problem is definitely in my apache configuration. It might be something in the vhost.conf file, or it might be something in the httpd.conf file. I'm not really sure, and it doesn't help that I'm a n00b at apache. Based on my research I do think it is something to do with AllowOverride, but I'm just not sure what. It may need to be in a <Directory> bracket. I'm not completely sure. Need to do more research but if you guys can point me in the right direction that would be awesome.
#4

[eluser]skcin7[/eluser]
I figured it out. It was a setting with my apache configuration. My .htaccess file wasn't being read whatsoever.

I had to locate my httpd.conf file and change AllowOverride to "ALL"




Theme © iAndrew 2016 - Forum software by © MyBB