Htaccess rewrite on temporary cPanel URL

Hi,

I’m trying to create a rewrite on a temporary URL. For example the URL is http://31.222.170.22/~matchin2

Here are the rules I have setup in my htaccess file…


RewriteEngine on
RewriteBase /~matchin2
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /page.php [L]

However, this doesn’t seem to work. If I go to http://31.222.170.22/~matchin2/about

then I would expect it to do a redirect to page.php but it doesn’t seem to be triggering.

The above code works fine on websites like www.google.com but will not work for IPs and temporary URLs. Does anyone know how I can change the above code so it can work on IPs/temporary URLs?

Thanks.

Hi Zaggs!

First, where is this .htaccess file located? IMHO, it should be in the ~matchin2 subdirectory which would alleviate the need for the RewriteBase. On the assumption that index.php exists in the ~matchin2 subdirectory, it’s covered by the !-f so your first RewriteRule can also be eliminated. Finally, /page.php as a redirection is first tried in the server’s root then in the domain’s DocumentRoot so I’d eliminate the / (if page.php is in the ~matchin2 subdirectory).

# remove the [COLOR="#FF0000"]red[/COLOR], add the [COLOR="#0000FF"]blue[/COLOR], remove the [COLOR="#808080"]gray[/COLOR] after testing
RewriteEngine on
[COLOR="#FF0000"]RewriteBase /~matchin2
RewriteRule ^index\\.php$ - [L][/COLOR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .[COLOR="#0000FF"]?[/COLOR] [COLOR="#FF0000"]/[/COLOR]page.php [[COLOR="#808080"]R=301,[/COLOR]L]

Tip: Use the R=301 flag for testing so you see whether/what redirection has been issued by mod_rewrite.

Regards,

DK

Hi David,

Thanks for this. I tried what you posted above but it doesn’t seem to like it. When I goto my url, for example: http://31.222.170.22/~matchin2/about

It should redirect to http://31.222.170.22/~matchin2/page.php BUT instead it redirects to http://31.222.170.22/page.php

What am I missing?

Thanks.

Zaggs,

Not you! I had interpreted your problem as eliminating the ~matchin2 (or misinterpreted the effect of the RewriteBase - too late to think tonight, er, this morning). Give this a try:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .? /~matchin2/page.php [R=301,L]

When that fails, please redefine exactly what you’re asking for and I’ll attack it in the morning.

Regards,

DK

You’re a star! Works for me now, thanks.

Zaggs,

What? :eek2: I was actually awake last night?

Regards,

DK