Mod_ReWrite kills my site :-(

Associate
Joined
19 Jun 2003
Posts
1,680
Location
West Yorks, UK
Hi all,
I run a Linux web server (Fedora Core 3, Apache 2 etc etc). I'm trying to use mod_rewrite on some of my sites, but when I add "ReWriteEngine On" to my .htaccess file, I get a 500 Internal Server Error. I have "Options All" in my main httpd.conf and then in my vhost.conf (where virtual sites info is kept), I have:

Code:
<Location />
       Options +Includes
</Location>
<Directory /home/default/websitename.co.uk/user/htdocs/>
       AllowOverride AuthConfig Limit Indexes
</Directory>

Have I done something daft? The mod_rewrite is definately being loaded - I wondered if I hadn't got the right options or overrides in place? Any ideas?

Matt
 
Ah, it needed AllowOverrides All i think.

So, I no longer get any errors, but it does nothing either! I have a url that is "/portfolio/view.php?id=1" that I want to change to "/portfolio/view/1", so I've tried this:
Code:
ReWriteEngine On
RewriteBase /
RewriteRule ^/portfolio/view/(.*)/$ /portfolio/view.php?ID=$1

But it does nothing. Where am I going wrong? I've restarted Apache (do I need to do this when I change a rewrite rule?), but it doesn't do anything :-S

Matt
 
Try changing ReWrite to Rewrite, I can't remember if it's case sensitive.

Other than that... are you adding the trailing / at the end of the URL, like in your regex? Also, you might have a problem with the folder in the path.

Try this, which also makes the trailing slash optional:

Code:
RewriteEngine On
RewriteBase /portfolio/
RewriteRule ^view/(.*)/?$ view.php?ID=$1
 
Cheers Rob - unfortunately, it makes no difference - the URL isn't rewritten at all. Wonder what on earth is going on? I can see mod_rewrite listed on phpInfo() under "Loaded Modules" though.

Any other possible things to try?

Matt
 
No joy i'm afraid - weird thing is, if I add the rewrite rules it does nothing, but if I add in an error into them (eg, change "RewriteRule" to "Rewrite_rule"), I get a 500 internal server error....

So it must be processing it, but just isn't acting on it?

Matt
 
Ok I know this is different to what you've got but it works on my server so it should work for you, give it a try...

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^portfolio/view/?$ view.php?id=$1 [NC]
 
Nope, no change. It has to be a config issue with Apache then. Its an odd setup - the server was supplied by Fasthosts, and runs their "Matrix Control Panel". Apache has a central config file (httpd.conf) and then the sites that are hosted on the server are listed in vhost.conf. The base settings are set in the httpd.conf I guess, and then overidden in vhost.conf, and then overidden some more in .htaccess. Must be something along the way there....

I'll copy in the important parts of each file below:

httpd.conf
Code:
LoadModule rewrite_module modules/mod_rewrite.so

<Directory />
    Options FollowSymLinks
    AllowOverride AuthConfig Indexes
</Directory>

<Directory "/var/www/html">
    MultiViews
    Options All
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

AccessFileName .htaccess

# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
</Files>

vhost.conf
Code:
Listen 80
ServerRoot "/etc/httpd"
<IfModule mod_dir.c>
    DirectoryIndex default.html default.htm index.html index.htm index.shtml     index.php index.php4$
</IfModule>

<VirtualHost [ip_address]:80 [ip_address]:80>
        ServerName [domain_name]
        ServerAlias [domain_name]
        ServerAdmin webmaster@[domain_name]
        DocumentRoot /home/default/[domain_name]/user/htdocs
        ErrorLog /home/default/[domain_name]/user/logfiles/error_log
        TransferLog /home/default/[domain_name]/user/logfiles/access_log
        php_admin_value open_basedir /tmp:/home/default/[domain_name]
        ErrorDocument 404 /errors/404.php
        SuexecUserGroup [domain_name] matrixdomain
        AddHandler server-parsed .shtml
        AddType text/html .shtml
        <Location />
                #Options +Includes
                #Options All
                Options +FollowSymLinks
        </Location>
        # AC
        <Directory /home/default/[domain_name]/user/htdocs/>
                #AllowOverride AuthConfig Limit Indexes
                AllowOverride All
                Options +FollowSymLinks
        </Directory>
# Begin user directives <--
# --> End user directives

Anything glaringly obvious there?

Matt
 
Will. However, I got the 500 when i put "RewriteEngine On", so i presume I got it when Apache wasn't set to allow all overrides in the .htaccess. Now, I can add the rules in fine without causing any errors - they just don't do anything!

Matt
 
Well, i'm back to the 500 internal server error now. I've made Apache virtually unrestricted in what it can handle, but as soon as I put on "RewriteEngine On", I get the 500 error. In my Apache error log for the site, I get:
Code:
[Wed May 24 13:04:18 2006] [alert] [client (ip address)] /home/default/(site name)/user/htdocs/.htaccess: RewriteEngine not allowed here

But, I can do the .htpasswd stuff in there for authentication. Does that point to anything more specific now?

Matt
 
Beansprout said:
What's your entire httpd.conf? Have you got...

Code:
AddModule mod_rewrite.c
In there anywhere?

Hi,
There are no "AddModule" lines in my httpd.conf at all - only "LoadModule" ones. The server runs Apache 2 by the way.

Matt
 
unknowndomain said:
surley thats implied by the fact that its loaded in phpinfo(); ?
Didn't read that part :o Wonder why it's not working..I'm not friendly with Apache2 :)

Try adding AllowOverride All to the <Directoy /> (might as well allow everything to get it working first).
 
Blah - changed everything to "All", and it hasn't worked. I will give it a try later, as I keep having to restart Apache and don't want to take the sites down for too long at a time.

Thanks for the help....

Matt
 
Back
Top Bottom