mod_rewrite code work

Sounds good to me, and achieves the same goal I suggested: first do a 301 to the correct URL, and then process further :slight_smile:

Roger. It’s still not working, and at the moment I am working though the tutorial (somewhat blindly) to try and see where it might be going wrong.

I know that


RewriteCond %{HTTP_HOST} hostingcompany\\.com [NC]
RewriteRule .? http://www.actualdomain.com%{REQUEST_URI} [R=301,L]

at least triggers a redirect on the ReWriteCond(itional) on

http://server.hostingcompany.com/~myhostingusername/

so I know I have access to be able the Apache variable.

But by all accounts the following should work, though having read the tutorial I want to ask why it doesn’t require a ^ at the beginning of the rule and why there is not a $ after (.*).


RewriteRule ~myhostingusername/?(.*) http://www.actualdomain.com/$1 [R=301,L]

You could add ^ and $ if you like, doesn’t matter (it will probably be slightly faster if you do though).

Location, Location, Location! Of course! WHERE is this code located? Horrors! It’s NOT in hostingcompany’s DocumentRoot which is what the RewriteRule assumes (er, requires)! REMOVE the red text from the RewriteRule and see if that doesn’t do the trick for you (if it doesn’t, add a / where the red text was located)!

Hmmm, as noted above, that’s in the subdirectory of hostingcompany so the ^ really doesn’t matter AND the (.*) is always “greedy” so that doesn’t matter, either.

DD, did you get to the point where you can separate the parts of the content/123/456/? Is content really fixed as content or can it be content, reviews, purchase, etc., or is it ANY (lowercase) string? The numeric values: ONE single digit? More than one? One to three? SPECIFICITY, if you please!

It looks like content/123/456/ can be matched with regex like ^(content|reviews|purchase)/([0-9]+)/([0-9]{1,3})/ where $1 (the first parenthetical) is any one of the three options listed, $2 is one or more digits and $3 is one, two or three digits. Get it now? Then the redirection can be to yourscript.php?type=$1&cat=$2&subcat=$3 [L] - NEVER forget the Last flag!

Regards,

DK

Oh joy of joys - that works precisely. Both the / and /{ANYTHING} versions redirect to the real / and /{ANYTHING} respectively per the specificity :).

Kudos to you both for your patience and forcing to actually understand a bit mroe about what I am doing here.

So a bit confused here because I as never trying to separate the parts was I - that rewrite was pre-existing?

The index.php of your CMS is probably able to grab the original URL from Apache.
I’m using the Yii PHP framework and this my only RewriteRule *:


RewriteRule . /index.php

As you can see everything is directed to index.php, which resolves the URL the user actually requested and takes action accordingly.

  • Not taking into account RewriteRules to force “www” etc

Okay that makes sense as those rules do look a little rudimentary at first glance :slight_smile: