Page 1 of 1

mod_rewrite working but not?

Posted: Tue Jan 18, 2011 4:44 am
by shiznatix
I am trying to move a website to a new host. The old host was running some flavor of Linux but now it will be put on a Windows server.

The problem I am having is with the mod_rewrite module. Although it is being loaded just fine, I can't seam to get anything to work. In the simplest situation, I have a directory structure like this:
[text]htdocs/
uudised/
index.php
index.php
.htaccess[/text]
Now I don't want to delete the uudised/ directory but I don't want it to be accessable either. I want everything to be moved to the htdocs/index.php file using mod_rewrite.

So, in the htdocs/.htaccess file I have this:
RewriteEngine on
RewriteCond %{ENV:REDIRECT_SCRIPT_URL} ^$
RewriteRule ^/uudised(.*)$ /index.php?page=uudised [L,PT]
Which is exactly how it was on the previous server. This gives no errors but still isn't working. I know the file is at least being loaded because if I write a line of garbage, apache throws me the internal server error so at least the file is being read.

As for the virtual host, this is the record:
<Virtualhost ###.###.##.###>
DocumentRoot "C:\www\www.example.ee\www.example.ee"
ServerName sub.example.com
Customlog C:\www\logs\sub.access.log combined
Errorlog C:\www\logs\sub.error.log
</VirtualHost>
Now my skills in apache and mod_rewrite are not so awesome so if I am missing something obvious here, please let me know. I can't think of anything and as far as I can tell, on server that is nearly 100% identical, there is no problem with mod_rewrite. Can someone shed some light on the situation?

Re: mod_rewrite working but not?

Posted: Tue Jan 18, 2011 9:08 am
by Darhazer
Try commenting the RewriteCond

Code: Select all

RewriteEngine on
#RewriteCond %{ENV:REDIRECT_SCRIPT_URL} ^$
RewriteRule ^/uudised(.*)$ /index.php?page=uudised [L,PT]

Re: mod_rewrite working but not?

Posted: Tue Jan 18, 2011 9:19 am
by shiznatix
Darhazer wrote:Try commenting the RewriteCond
No dice. Didn't change anything.

Re: mod_rewrite working but not?

Posted: Tue Jan 18, 2011 9:39 am
by Darhazer
Sometimes adding RewriteBase / helps
You can also simplify your Rule to
(.*)
to check if mod_rewrite catches the URL at all and if so - play with the rule

Re: mod_rewrite working but not?

Posted: Wed Jan 19, 2011 1:55 am
by shiznatix
Using this:[text]RewriteEngine on
RewriteBase /
#RewriteCond %{ENV:REDIRECT_SCRIPT_URL} ^$
#RewriteRule ^/uudised(.*)$ /index.php?page=uudised [L,PT]
RewriteRules ^/(.*)$ index.php[/text]
Still does nothing. I still go to the directory uudised/ instead of being served index.php

Re: mod_rewrite working but not?

Posted: Wed Jan 19, 2011 2:21 am
by Darhazer
Try without the / in the Rule

Re: mod_rewrite working but not?

Posted: Wed Jan 19, 2011 7:19 am
by shiznatix
This simple .htaccess does not do anything:
[text]RewriteEngine on
RewriteBase /
RewriteRules ^(.*)$ index.php[/text]

Re: mod_rewrite working but not?

Posted: Wed Jan 19, 2011 8:59 am
by Weirdan
Should be RewriteRule, not RewriteRules.

Re: mod_rewrite working but not?

Posted: Wed Jan 19, 2011 9:06 am
by shiznatix
Ha, funny but still no dice with this:[text]RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ index.php[/text]

Re: mod_rewrite working but not?

Posted: Wed Jan 19, 2011 9:20 am
by Weirdan

Code: Select all

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

Re: mod_rewrite working but not?

Posted: Thu Jan 20, 2011 3:21 am
by shiznatix
Nothing. Still won't work
Weirdan wrote:

Code: Select all

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

Re: mod_rewrite working but not?

Posted: Thu Jan 20, 2011 3:53 am
by Darhazer
Enable the RewriteLog and set the RewriteLogLevel then see what is in the log.
If there is no log at all, then the module is not loaded. Why it does not give an error is another topic. By the way, RewriteRules had to raise error
How do you test that the .htaccess is loaded at all?
Do you have AllowOverride all in the httpd.conf ?

Re: mod_rewrite working but not?

Posted: Thu Jan 20, 2011 6:58 am
by shiznatix
[text]RewriteEngine on
RewriteLogLevel 3
RewriteLog "C:/www/www.example.ee/log.txt"
RewriteBase /
RewriteRule ^(.*)$ index.php [L][/text]

Nothing shows up in log.txt no matter what

Re: mod_rewrite working but not?

Posted: Thu Jan 20, 2011 7:13 am
by Darhazer
check httpd.conf for AllowOverride directives