Welcome Guest, Not a member yet? Register   Sign In
Urgent mod_rewrite problem
#1

[eluser]simsab[/eluser]
Hey folks,

I have a problem with the rewrite rules. My CodeIgniter application is running in a sub-directory (domain.tld/alpha/) on a virtual server with CentOS and PLESK. When I browse to domain.tld/alpha/ the front page shows correctly but none of the links work (i.e. domain.tld/alpha/Help for the Help controller).

I have tried a lot (!) and read myself through tons of forum threads and blogs but still cannot get the routes to work properly.

Here is my .htaccess file:
Code:
Options -Indexes
Options +FollowSymLinks
Options -MultiViews

DirectoryIndex index.php

RewriteEngine on

RewriteBase /alpha/
#RewriteBase /alpha
#RewriteBase /

RewriteCond $1 !^robots\.txt
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

#RewriteRule ^(.*)$ index.php?$1 [NC,L,QSA]
#RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
RewriteRule ^(.*)$ /alpha/index.php?/$1 [NC,L,QSA]
As you'll already have figured out I have tried various RewriteRules (including / or not, setting the rewrite base or not, including ? or not etc.).

My config.php:
Code:
<?php
//...
$config['base_url']    = '/alpha/';
//...
$config['index_page'] = '';
//$config['index_page'] = 'index.php';
//...
//$config['uri_protocol'] = "QUERY_STRING";
$config['uri_protocol'] = "AUTO";
//...
$config['enable_query_strings'] = FALSE;
//$config['enable_query_strings'] = TRUE;
//...
?>
I changed every setting here, too (especially the uri_protocol) - without success. Even when I change the index_page to index.php it doesn't work when I access the site via domain.tld/alpha/index.php/...

Also, I added some custom lines to my httpd.conf file and restartet the httpd numerous times:
Code:
<Directory "/var/www/vhosts/domain.tld/httpdocs/alpha">
#<Directory /var/www/vhosts/domain.tld/httpdocs/alpha>
    Options All
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
No effect at all.

Next, I set up a simple index.php in the root directory of the application to check what the .htaccess redirects to:
Code:
&lt;?php
print_r($_SERVER);
?&gt;
The result for domain.tld/alpha/ is:
Code:
Array
(
    [HTTP_HOST] => domain.tld
    [...]
    [PATH] => /sbin:/usr/sbin:/bin:/usr/bin
    [SERVER_SIGNATURE] =>
Apache/2.2.3 (CentOS) Server at domain.tld Port 80


    [SERVER_SOFTWARE] => Apache/2.2.3 (CentOS)
    [SERVER_NAME] => domain.tld
    [...]
    [SERVER_PORT] => 80
    [...]
    [DOCUMENT_ROOT] => /var/www/vhosts/domain.tld/httpdocs
    [SERVER_ADMIN] => [email protected]
    [SCRIPT_FILENAME] => /var/www/vhosts/domain.tld/httpdocs/alpha/index.php
    [REMOTE_PORT] => 56375
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] =>
    [REQUEST_URI] => /alpha/
    [SCRIPT_NAME] => /alpha/index.php
    [PHP_SELF] => /alpha/index.php
    [REQUEST_TIME] => 1260416939
)
The result for domain.tld/alpha/Help is:
Code:
Array
(
    [REDIRECT_STATUS] => 200
    [...]
    [PATH] => /sbin:/usr/sbin:/bin:/usr/bin
    [SERVER_SIGNATURE] =>
Apache/2.2.3 (CentOS) Server at domain.tld Port 80


    [SERVER_SOFTWARE] => Apache/2.2.3 (CentOS)
    [SERVER_NAME] => domain.tld
    [...]
    [SERVER_PORT] => 80
    [...]
    [DOCUMENT_ROOT] => /var/www/vhosts/domain.tld/httpdocs
    [SERVER_ADMIN] => [email protected]
    [SCRIPT_FILENAME] => /var/www/vhosts/domain.tld/httpdocs/alpha/index.php
    [REMOTE_PORT] => 56370
    [REDIRECT_QUERY_STRING] => /Help
    [REDIRECT_URL] => /alpha/Help
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] => /Help
    [REQUEST_URI] => /alpha/Help
    [SCRIPT_NAME] => /alpha/index.php
    [PHP_SELF] => /alpha/index.php
    [REQUEST_TIME] => 1260416928
)

Now, you experts - I really, really hope someone here can help me. Unfortunately, this one is an urgent thing as the deadline for the launch is tomorrow (Friday). Please, guys!

Many thanks in advance,
Simon
#2

[eluser]theprodigy[/eluser]
you should be able to use the htaccess file located in the wiki (here) and place that file inside your CodeIgniter home directory (domain.tld/alpha).

The htaccess should reside in your CodeIgniter home (where your index.php file resides), not necessarily your domain home.
#3

[eluser]simsab[/eluser]
Hi theprodigy, thanks for your reply.

I have tried everything the wiki page suggests and much more. Nothing has worked for my configuration so far.
The .htaccess file I have posted above is located in the alpha sub-directory.
I just tried this in the httpd.conf file:
Code:
<VirtualHost *>
        ServerName www.domain.tld
        DocumentRoot /var/www/vhosts/domain.tld/httpdocs/alpha
        <Directory /var/www/vhosts/domain.tld/httpdocs/alpha>
                RewriteEngine On
                RewriteBase /
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^(.*)$ index.php/$1 [L]
        </Directory>
</VirtualHost>
It doesn't change a thing.

This seems to be some kind of weird issue with my virtual server. If only someone knew an answer to it, I really have to be done by tomorrow and I'm getting really nervous about it.
#4

[eluser]theprodigy[/eluser]
ok, two questions.

1. Who are you hosting with? Some hosters (like GoDaddy) have a slightly different htaccess file needed.

2. Have you verified that mod_rewrite is installed and enabled?
#5

[eluser]simsab[/eluser]
1. It's a German provider called server4you.de - reading through all those forum threads and stumbling upon problems with GoDaddy I have already tried a different syntax for the .htaccess file - without effect of course.

2. Yes, in the root directory of domain.tld there is also an application running on Drupal that uses RewriteRules. It doesn't interfere with the CodeIgniter app in domain.tld/alpha/ though. As I said, the front page of the CI app shows up and instead of showing sub-pages for each controller I get a 404 error page from CodeIgniter.
#6

[eluser]Jeroen Brussich[/eluser]
Could you please post what you expect your .htaccess should do.

It is easier for us to work towards a solution then trying to deduct one...
#7

[eluser]theprodigy[/eluser]
do your sub-pages show fine if you include the index.php in the url? domain.tld/alpha/index.php/Help?

I ran into some issues before with capitalization (domain.tld/alpha/Help may not work, but domain.tld/alpha/index.php/help will).
Or you may want to check your URI_PROTOCOL setting in your config.php. My hoster doesn't work with auto. I have to set it to another option (REQUEST_URI).
#8

[eluser]simsab[/eluser]
Oh my theprodigy, it really is an issue of case-sensitiveness!
domain.tld/help works just fine.. Wow, this was really driving me mad.
Thank you so much for your hint!

Now why exactly does the flag NC not make the RewriteRule tolerate Help also?
Am I thinking twistedly? (It's 7 A.M. here in Germany and I have been up
all night to solve this problem.)

Many, many thanks!

/edit: Oh no, wait - of course it does not tolerate capitalized requests
as they are not directly matched but only passed through (.*).
I guess that's the pay-off for developing on a case-insensitive Windows machine...
#9

[eluser]theprodigy[/eluser]
glad I could help.
I'm not sure why NC doesn't seem to always work, but at least we figured it out.
Good luck on the rest of your project!
Let us know if you need any other help.
#10

[eluser]simsab[/eluser]
Just for the record, it now works with this very basic configuration:
config.php
Code:
$config['uri_protocol'] = 'AUTO';

.htaccess
Code:
Options -Indexes
Options +FollowSymLinks
Options -MultiViews

DirectoryIndex index.php

RewriteEngine on

RewriteCond $1 !^robots\.txt
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /alpha/index.php?/$1 [NC,L,QSA]

and without any changes to httpd.conf

Rock on, guys!




Theme © iAndrew 2016 - Forum software by © MyBB