Forum Moderators: phranque

Message Too Old, No Replies

Another Rewrite Quesition.

         

Azrhei

12:56 am on Sep 5, 2009 (gmt 0)

10+ Year Member



Ok, I used to have a domain (well still have)

I had http://example.com/blog/
And now I have simply http://example.com/

I had http://blog.example.com/
And now I have simply http://example.com/

I also had http://blog.olddomain.org/
which needs to be http://example.com/

All the same example.com above.

I need both to redirect correctly while preserving the path / query string (which have never changed)

What I've got so far is :
RewriteBase /
RewriteRule ^blog/(.*)$ /$1 [R=301,NC,L]

Which works perfect and fast.

I've Google'd and tried many solutions (which to my limited knowledge of mod_rewrite, should work)
I even worked it myself first (and then went to Google)
Many of the solutions were from here.

If it matters... I used Godaddy Shared Unlimited Hosting

[edited by: jdMorgan at 1:32 am (utc) on Sep. 5, 2009]
[edit reason] example.com [/edit]

jdMorgan

1:36 am on Sep 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest including the canonical hostname:

RewriteRule ^blog/(.*)$ http://example.com/$1 [NC,R=301,L]

Then all you need is a second rule (after this one) to redirect requests for any hostname other than blank or *exactly* example.com to example.com, passing the URL-path through as in the rule above. The query strings (if any) will pass through the rules unchanged by default.

There are plenty of examples of domain canonicalization rules posted here -- at least one today, in fact.

Jim

Azrhei

1:53 am on Sep 5, 2009 (gmt 0)

10+ Year Member


Thanks, that solves the one I've already solved :) (and just a bit faster)

But the other examples are the ones I'm struggling with...I've tried at least 5 unique examples, (and many variations on those) and all return Forbidden

The result I get is : "You don't have permission to access /author/category/title on this server."
(where I've replaced the names on the path)

I could just create a subdomain pointed to a folder and then use a PHP/JavaScript redirect to correct...but that tends to be slower with my experience.

The last example problem's solution would go on the old server (which I still have control of, so I could do it) (the old server is being used to host a different domain I own)

jdMorgan

2:44 am on Sep 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I've tried at least 5 unique examples, (and many variations on those) and all return Forbidden

Well, if you'd post one of these, we would have a basis for discussion. (If this statement isn't clear, a review of our Forum Charter would be recommended.)

You'll need a RewriteCond examining %{HTTP_HOST} on the old server if you've got two domains (one that you want to redirect, and one that you don't) both pointed to the same filespace on that server.

Thanks,
Jim