Unable to Remove index.php on ExpressionEngine WAMP Installation - .htaccess

I have WAMP v2.2 installed on my Windows 7 machine, with virtual hosts enabled.
I've successfully installed ExpressionEngine for one of my local sites, and everything works great except when I try to remove index.php from the URL using the approved .htaccess method. I still get a 404 error if index.php is not present, but the page displays fine with index.php in the URL.
I made sure the rewrite module was checked in the Apache menu:
. I've successfully used this method dozens of times on commercial hosts, so I'm stumped.
Update for pvledoux:
<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# If 404s, "No Input File" or every URL returns the same thing
# make it /index.php?/$1 above (add the question mark)
</IfModule>
Note: I tried adding the ? into the rule, but it didn't work.
The site is at the root of the Virtual Host.

Got It!
I needed to add AllowOverride in httpd-vhosts.conf:
<Directory "C:\Site\Root\Path">
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
A gagillion thanks and a 6-pack of beer goes to #parhamr for helping me out of this pickle.

A few possibilities here you could try out here:
[...]
RewriteEngine On
Options FollowSymLinks
[...]
Or:
[...]
RewriteEngine On
Options +MultiViews
[...]
Or:
[...]
RewriteEngine On
Options FollowSymLinks
Options +MultiViews
[...]
From my experience, Apache when running on Windows often needs one or both of those in order to do these kinds of things correctly. It might also straight up 500 on you, but these have worked for me in the past.

try to add RewriteBase /
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# If 404s, "No Input File" or every URL returns the same thing
# make it /index.php?/$1 above (add the question mark)
</IfModule>
and check for sure that mod_rewrite is active in phpinfo

Have you checked your default document in Apache? If you are removing index.php physically from the machine and it reports a 404 on just a directory, www.domain.com/home/ that means Apache is looking for index.php still.

Is mod_rewrite turned on in the Apache?

Related

HTACCESS Rewrite not working on Ubuntu 14, Apache2

First of All I'm not an expert on Linux, or even Apache, I'm used to work on Windows, WAMP where you just right clic on the icon and change the configuration you want to change.
Right now I have LAMP working properly, the only thing that is not working is the HTACCESS rewrite:
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
This is a common HTACCESS setup.
Everytime I write the URL: localhost/mysite/services it throws a 404 error.
You have to know that I've tried everything I've seen in Stackoverflow and Ubuntu forums.
1) When I check if the mod rewrite is active, it says it is
2) I created a "default.conf" file in "/etc/apache2/sites-available" and put this inside:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/
</Directory>
3) I've restarted the apache2 service after that
Nothing seems to work, I'm desperated because I have to get this done for tomorrow.
EDIT:
This exactly configuration WORKS on Windows-WAMP and Production Server (hostgator)... I just pasted all the app to my Ubuntu Laptop and here, it is not working.
I am using apache2 in Ubuntu 14 and this works fine for me.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|hme|img|editor|tsd|wd|images|edi|js|fonts|assets|robots\.txt|css|blog)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Hope this helps.

Codeigniter URL rewriting .htaccess is not working on CentOS

I've created a .htaccess file in my document root at /var/www/html/ to rewrite URL of Codeigniter to remove "index.php" from URL of all pages.
e.g. Change URL from
http://myhost/index.php/controller/function
to
http://myhost/controller/function`
Here is the code of my `/var/www/html/.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I've got many suggestions from googling to enable mod-rewrite module, but I can see in my httpd.conf its already enabled.
LoadModule rewrite_module modules/mod_rewrite.so
This is perfectly working on my local system running on Debian 7 (Apache/2.4.4).
Any help would be appreciated. :)
You need to also specify the locations that can use it. For example, in /etc/httpd/conf/httpd.conf you should see something like:
<Directory "/var/www/html">
...lots of text...
</Directory>
Make sure is has:
<Directory "/var/www/html">
AllowOverride All
</Directory>
It's possible that your centos server isn't setup to handle PATH INFO. Try replacing the index.php/$1 in your rule's target to index.php?/$1.
Then you need to modify your CI config to enable query strings: http://ellislab.com/codeigniter/user-guide/general/urls.html
In you application/config.php file set $config['enable_query_strings'] to TRUE.
# CentOS Linux release 7.9.2009 (Core) -
# CodeIgniter 3.1.11 - ( .htaccess - This code work for me )
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Codeigniter - removing the index.php

I've been trying for hours and could not make it work. Searched for answers everywhere, and nothing seems to solve my problem.
I even tried the solutions described here: Remove index.php in codeigniter 2.1.0. No luck at all.
I have set the config['index_page'] as ''.
My .htaccess is on the root folder (where the sys and app folders are) and is written like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Still, the only way I can access my controller methods is with the goddamn index.php in the url.
And yes, my apache conf has mod rewrite enabled.
ANY HELP would be incredibly nice.
EDIT
I´ll add some more info, maybe it's relevant.
I´m using ZendServer.
I´m working at localhost by now.
RewriteEngine On
RewriteBase /yourdirectoryname/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
I have no experience on ZendServer, but tonight I also got this problem on localhost using xampp (without ZendServer), and finally got it worked :
check your httpd.conf, and make sure "LoadModule rewrite_module modules/mod_rewrite.so" line is not commented.
open config.php, set $config['base_url'] = 'http://localhost/yourdirectoryname/'
still in config.php, set $config['index_page'] = ''
create .htaccess file on the same directory with your index.php (in my case, htdocs/yourdirectoryname)
the content of that .htaccess file is as above
I have no experience with code igniter, but if I understand correctly you are trying to serve something like /index.php/my-page to the user, without the need for him to prepend index.php to it?
If I'm correct, you could try something like this:
RewriteBase / # make sure we always rewrite from within the root directory
RewriteCond %{REQUEST_FILENAME} !-f # make sure the request is not to an existing file
RewriteCond %{REQUEST_FILENAME} !-d # nor an existing directory
RewriteCond %{REQUEST_FILENAME} !^index\.php # make sure we do only interpret requests that DO NOT start with index.php
RewriteRule ^(.*)$ index.php/$1 [L,QSA] # interpret request as if it were to index.php/...
# make sure we do only interpret requests that DO start with index.php
RewriteRule ^index\.php/(.*)$ $1 [L,R,QSA] # redirect user to new URL, which will be handled by the first rewriterule
Keep me posted whether this works or not
try this one, i've used this on many hosts anywhere , check:
RewriteEngine On
RewriteBase /yoursitedirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
if is not enought then go to config.php file and search for this line:
|--------------------------------------------------------------------------
| 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';
i use AUTO but you maybe need to switch that to REQUEST_URI or QUERY_STRING, try
I finally managed to work this out. Thanks for all the answers, special thanks to #ddanurwenda. His rewrite rules were the only ones that solved my problem.
There was an Apache config that I had overlooked: I changed this line (from httpd.conf):
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
To the following:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>
That configuration were keeping my htaccess file from being read.
This is what I use and works.
Use this code in your .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* website/index.php/$0 [PT,L]
Just make sure the .htaccess is in your root folder. (ie: xampp/htdocs)
Then in your config.php(application\config) replace
config['index_page']='index.php'
to
config['index_page']=''.

.htaccess not working on live site but working on localhost?

I am using ExpressionEngine and want to remove index.php from my URL's. I have this .htaccess file saved in the root folder. It works perfectly on localhost but when I upload it to the server it doesn't work. The correct URL appears in the address bar but the page stays on homepage. Any tips?
<IfModule mod_rewrite.c>
# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /
# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteCond %{THE_REQUEST} ^GET
RewriteRule ^index\.php(.+) $1 [R=301,L]
# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
Make sure your AllowOverride Directive in Apache is configured to allow .htaccess files and your server has mod_rewrite installed and active.
On Mac OS X, you'll find this file at /etc/apache2/httpd.conf. Look for the <Directory> Directive and change it to be:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
</Directory>
You'll need to restart Apache so it can read the new configuration:
sudo /usr/sbin/apachectl restart
If you'd prefer to use a GUI to restart Apache, go to Apple > System Preferences > Sharing and toggle the checkbox next to the Web Sharing service.
If you're using Windows or any flavor of Linux, the same approach applies, but the Apache configuration may be in a different place, especially if you're using WAMP or MAMP.
Also, for reference, the "officially supported method" by EllisLab for Removing index.php from ExpressionEngine URLs is the following:
<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# If 404s, "No Input File" or every URL returns the same thing
# make it /index.php?/$1 above (add the question mark)
</IfModule>

.htaccess and internal server error

I've been trying to set up .htaccess to create clean PHP URL. My goal is to achieve clean URLs within the folder CL.
.htaccess:
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
<IfModule mod_rewrite.c>
# This is the initialization
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
# /CL/var1/var2/var3
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^CL/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ /CL/index.php?var1=$1&var2=$2&var3=$3 [L,QSA]
# /CL/var1/var2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^CL/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ /CL/index.php?var1=$1&var2=$2 [L,QSA]
# /CL/var1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^CL/([a-zA-Z0-9\-]+)/?$ /CL/index.php?var1=$1 [L,QSA]
</IfModule>
However, for some reason, I get a 500 internal server error when y enter the folder CL. I've used similar .htaccess configurations in the past, but now its not working fore some reason.
Any ideas?
"I've used similar .htaccess configurations in the past, but now its not working fore some reason."
OK, so the ruleset works. I've just tested in on one my test VMs so it still works, so your problem isn't the mod_rewrite functionality in this .htaccess file. So where could it be?
Think laterally. A 500 status is usually a mod_rewrite loop. Have you got an .htaccess file in /CL? This could create a perdir indefinite loop.
Unfortunately DS suggestion of trying to get an answer on error_log content from a shared hosting provider for a $100 pa shared service is a no-no. Morale: set up a test VM on your PC to debug this stuff where you can get root access to the log as article here.

Resources