A little htaccess help

I’m moving a site to a new host and keeping the same domain name. Seems the same unaltered htaccess file would work for me…

Here’s what I’ve got:

DirectoryIndex index.php
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ index.php?var1=$1 [L,QSA]

The file is being recognized, as it properly going to index.php.

However, nothing else is working.

First, I’m having to use a temporary url to browse the site until we switch the domain pointers. Looks like:
http://myipaddress/~myusername/

This properly resolves to the index page.

These work on the old site:
http://www.mysite.com/index.php?var1=faq
http://www.mysite.com/index.php?var1=contact
http://www.mysite.com/index.php?var1=privacy-statement

Also on the old site, these redirect properly to the above:
http://www.mysite.com/faq
http://www.mysite.com/contact
http://www.mysite.com/privacy-statement

These work on the NEW site:
http://myipaddress/~myusername/index.php?var1=faq
http://myipaddress/~myusername/index.php?var1=contact
http://myipaddress/~myusername/index.php?var1=privacy-statement

These do NOT work on the new site…
http://myipaddress/~myusername/faq
http://myipaddress/~myusername/contact
http://myipaddress/~myusername/privacy-statement

Suggestions?

I think you have a stray slash.

RewriteRule [1]//COLOR$ index.php?var1=$1 [L,QSA]

…should be…

RewriteRule ^(.*)$ index.php?var1=$1 [L,QSA]

Frankly, I’m surprised this worked on the old site.


  1. COLOR=“#FF0000↩︎

With the slash, clicking on a link “contact”, takes me to:
http://myipaddress/~myusername/contact … and a 404 on the page

Without: RewriteRule ^(.*)$ index.php?var1=$1 [L,QSA] - clicking a link “contact” takes me to:
http://myipaddress/404.html

Tried it both ways previously…

If I change the link itself to “/contact” …
Same thing as the above.

Les,

The leading / is only required in the older (now ancient) Apache 1 servers so eliminate it as Jeff suggested.

You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.

Regards,

DK

That’s actually not correct, as I’ve already explained. I’ve given you the exact spot in the documentation you need to check, and I’ve given you repeatable steps to test the behavior in Apache itself.

Unfortunately anyone who learns from this tutorial will have to unlearn some incorrect information later on (the above is one such example). I strongly recommend that anyone who’s interested in this topic go straight to the definitive source for the most complete, authoritative, and correct information.