Welcome to WebmasterWorld Guest from 54.221.30.139

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Having problems re-directing old subdirectory to subdomain

     

innocbystr

6:38 pm on Dec 26, 2012 (gmt 0)

10+ Year Member



I recently replaced by Joomla 1.5 site with Joomla 2.5. I moved the old 1.5 site to a subdomain: archive.example.com. I am trying to redirect some of the old urls that appear in the SERPS to their new location in the archive sub-domain (these are urls that no longer exist in the root/new site). In particular the first re-direct I am attempting is:

example.com/blog/ to archive.example.com/blog/

I have been through many WebmasterWorld posts on this (Google search: redirect entire site site:webmasterworld.com) as well as other forums and sites, have tried many examples, i.e. Redirect 301, RedirectMatch 301, and some mod-rewrites with no luck. The best I have been able to achieve is a redirect to the blog front page, archive.example.com/blog.html, when entering a specific blog post: example.com/blog/blogpost01.html.

I have successfully used re-directs in the past and have not had any problems. This seems like it would be a simple one, I must be missing something somewhere but I don't know what. Any advice would be greatly appreciated.

g1smd

7:09 pm on Dec 26, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



It's difficult to tell you where you went wrong when you supplied no code.

Make sure you have the very latest htaccess file; get it from a very recent Joomla package. Do this even if you are continuing to use an old version of Joomla.

The redirects will need to go in the htaccess file in the root of the old site. They'll go before the non-www/www redirect and after any code that blocks access to malicious requests.

Do not use Redirect or RedirectMatch. Use only RewriteRule with both the R=301 and L flags. The target URL must include the protocol and hostname.

Make sure the RegEx pattern is start anchored and that all literal periods are escaped.

lucy24

8:56 pm on Dec 26, 2012 (gmt 0)

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



these are urls that no longer exist in the root/new site

As long as one person or one robot requests it, the URL exists. Have you physically moved any material, or is it "only" your URL structure that has changed?

You cannot use mod_alias (Redirect by that name) because it looks only at the requested path. You need mod_rewrite with a RewriteCond that looks at the requested domain name (either example.com or subdomain.example.com).

Are you still using (www.)example.com for anything, or do you want to point everything to the subdomain?

If you had no redirects/rewrites in place, where would requests for the subdomain end up? If it lives in a directory that is physically* inside the main-domain directory-- this is the most common setup-- then all requests for the subdirectory will pass through the main domain's htaccess.


* Yes, OK, for a given definition of "physically". Your server is not made out of manila file folders. But we don't usually need to go there.

innocbystr

10:22 pm on Dec 26, 2012 (gmt 0)

10+ Year Member



Thanks all. I feel kind of silly now. While looking for a RewriteRule example I ran across a post that mentioned that cPanel has a redirect writing gizmo. Didn't host with anyone that had cPanel until recently and then never paid much attention to it. Anyway this is what it came up with:

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^blog\/?(.*)$ "http\:\/\/archive\.example\.com\/blog\/$1" [R=301,L]

Glad it works. I don't put on my 'developer hat' very often and have no idea what most of it means or what it does. I'll have to look for some sort of 'Dummies guide to .htaccess'. Don't really like using wysiwyg widgets but in this case useful.

g1smd

10:46 pm on Dec 26, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



You missed the further post that said that cPanel writes the absolute worst mod_rewrite code on the planet.

There are very many syntax and logic errors in that code.

The hostname tests don't capture all non-canonical versions such as example.com:80 etc. In any case the code doesn't need to test the requested hostname if the code is in the right htaccess file.

Slashes in patterns don't need escaping.

The rule target shouldn't be in quotes.

The escaping on the colons, slashes and periods in the rule target are all errors.

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

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

innocbystr

12:29 am on Dec 27, 2012 (gmt 0)

10+ Year Member



Thanks g1smd. Replaced cPanel hieroglyphics with yours and working fine. Wondered what in the world all those chicken scratches did. Glad I found out before I re-directed any more sub-directories.

g1smd

12:54 pm on Dec 27, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Whoever wrote the code for cPanel used the type of escaping that is used for JavaScript code, and didn't bother to look up exctly what escaping is needed for htaccess. You can instantly tell when a chunk of code was produced by cPanel.

The same errors are in use on tens of millions of websites.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month