mod_rewrite working but not?

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

mod_rewrite working but not?

Post 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?
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: mod_rewrite working but not?

Post by Darhazer »

Try commenting the RewriteCond

Code: Select all

RewriteEngine on
#RewriteCond %{ENV:REDIRECT_SCRIPT_URL} ^$
RewriteRule ^/uudised(.*)$ /index.php?page=uudised [L,PT]
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: mod_rewrite working but not?

Post by shiznatix »

Darhazer wrote:Try commenting the RewriteCond
No dice. Didn't change anything.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: mod_rewrite working but not?

Post 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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: mod_rewrite working but not?

Post 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
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: mod_rewrite working but not?

Post by Darhazer »

Try without the / in the Rule
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: mod_rewrite working but not?

Post by shiznatix »

This simple .htaccess does not do anything:
[text]RewriteEngine on
RewriteBase /
RewriteRules ^(.*)$ index.php[/text]
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: mod_rewrite working but not?

Post by Weirdan »

Should be RewriteRule, not RewriteRules.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: mod_rewrite working but not?

Post by shiznatix »

Ha, funny but still no dice with this:[text]RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ index.php[/text]
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: mod_rewrite working but not?

Post by Weirdan »

Code: Select all

RewriteRule ^(.*)$ index.php [L]
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: mod_rewrite working but not?

Post by shiznatix »

Nothing. Still won't work
Weirdan wrote:

Code: Select all

RewriteRule ^(.*)$ index.php [L]
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: mod_rewrite working but not?

Post 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 ?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: mod_rewrite working but not?

Post 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
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: mod_rewrite working but not?

Post by Darhazer »

check httpd.conf for AllowOverride directives
Post Reply