3

I am trying to remove the index.php from my URL, and have gone through the necessary steps, and used the code below in my .htaccess file. When I navigate to the homepage, it works, but clicking on any links, or typing their url in manually results in a 404. Just for poops and giggles, I added the index.php into the url of one of the sub-pages, and it started working fine. I've also tried adding the / before index.php in the code below to no avail, and I've tried with and without the ? after index.php. Any help you can provide would be amazing. Also, my site is in a subdirectory, ie, example.com/site-directory/index.php.

<IfModule mod_rewrite.c>
RewriteEngine On

# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
5
  • Are you sure that your server has mod_rewrite enabled? Commented Jan 17, 2013 at 13:10
  • Just to clarify: Are you using Apache as your webserver?
    – EpicVoyage
    Commented Jan 17, 2013 at 13:10
  • I use 1and1 and they do use Apache. Upon reviewing their documentation, I don't believe that mod_rewrite is enabled (faq.1and1.com/dedicated_servers/managed_server/2.html). How would I need to modify the above code to enable mod_rewrite? I'm new to this server configuration thing, so I apologize for my ignorance, but that's why I'm here right?
    – hyphen81
    Commented Jan 17, 2013 at 13:24
  • 1
    You'll have to ask them to enable it for you, unless their control panel offers an interface for this. Commented Jan 17, 2013 at 13:32
  • according to their technical support, it is enabled on their linux based packages, which is what I have. I read someplace else online that I might need to use "AllowOverride all" for it to even recognize my htaccess file. I will try this tonight and see if it works.
    – hyphen81
    Commented Jan 18, 2013 at 17:39

3 Answers 3

6

Because EE (and CI) run all page requests from a single index.php they must pull in the dynamic data from the URL. In general it does this via the server environment variable PATH_INFO. The problem, though, is that not all servers have this environment variable set. That's why EE and CI allow you to change how the URI is read.

In some cases the environment doesn't have PATH_INFO as an option. In those cases the system tries to "auto" select the right value but it doesn't always work.

Try changing the value of $config['uri_protocol'] in your system/expressionengine/config/config.php file. The possible values are listed in the file. Loop through those and save each time, refreshing the website when you're done. See if any of those different options fix the problem.

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'       Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'     Uses the REQUEST_URI
| 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';
0

try adding the path like so:

RewriteRule ^(.*)$ /site_directory/index.php?/$1 [L]

EDIT:

Sometimes Apache can be set up different from server to server.

i. e. on DreamHost this would work

RewriteRule ^(.*)$ /site_directory/index.php?/$1 [L]

Where as on my Ubuntu VM or EngineHosting this works

RewriteRule ^(.*)$ /ci/index.php/$1 [L]

Try removing the "?" after index.php

4
  • That didn't work for me. It seems to be somehow related to the "index.php" portion of the URL. When I plug that in, I can get to any page on my site.
    – hyphen81
    Commented Jan 17, 2013 at 13:02
  • That's the normal configuration of an ExpressionEngine site (including an index.php). The index file processes all your page requests through the content management system. You are trying to remove the index.php file, but still have it process all requests through EE. You'll need to start w/Derek's suggestion of contacting your ISP. Not all servers will allow for the removal of the index.php file. But having mod_rewrite enabled is the first step. Commented Jan 17, 2013 at 16:20
  • 1and1 tells me that mod_rewrite is enabled. After a while of banging my head against the wall, it seems that my .htaccess file is not even being recognized, but everything in 1and1's documentation says that its supported. I've tried the allowoverride all bit in my file and it isn't working either. I typed a bunch of garbage in the htaccess file, and it didn't effect anything either. However, if i go one level up to my main hosting directory (this site is in a sub-directory), and I put an htaccess file in that directory with garbage in it, I get a 500 error. I'm stumped.
    – hyphen81
    Commented Jan 21, 2013 at 16:27
  • also, I'm not sure if its related, but my EE system folder is one level up from my site directory as was recommended in the EE documentation for security purposes.
    – hyphen81
    Commented Jan 21, 2013 at 16:28
0

If you find yourself in a situation where you cannot get mod_rewrite turned on, I have seen this used in .htaccess files (credits to Elliot Haughin):

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.