Forum Moderators: phranque

Message Too Old, No Replies

301 root redirect to subdomain

         

amazingm

2:30 pm on May 29, 2008 (gmt 0)

10+ Year Member



I moved my blog from domain.com to sub.domain.com and I'm trying to redirect five posts.

Redirect 301 /post_name [sub.domain.com...] throws me into a loop.

I explained to hosting support my problem and I was told that I needed to add a condition before each rewrite rule that logically checks for something equivalent to "if the hostname of URL does not equal sub.domain.com" then entering rewrite rules but, being a newbie at this, I have no idea how to accomplish that.

I want to redirect domain.com/post_name to sub.domain.com/post_name (five posts).

I have also tried

RewriteEngine On
RewriteCond %{HTTP_HOST} !^sub\.domain\.com$ [NC]
RewriteRule ^(post_name1¦post_name2¦post_name3¦post_name4¦post_name5)$ [sub.domain.com...] [R=301,L]

with no success.

I'd appreciate any help.

jdMorgan

3:50 pm on May 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please define "no success" in detail: How did you test? What were the results? How did these results differ from your expectations? Did you completely flush your browser cache before testing the new server configuration?

Your code is correct as far as it goes, but perhaps there is something missing or hidden in the obscured details. For example, some servers will require the line:

Options +FollowSymLinks

or
Options +FollowSymLinks -MultiViews

before "RewriteEngine on", while others won't require it, and still others won't allow it and will throw a server error -- it depends on how your server is configured.

Another potential problem is the broken pipe "¦" characters. You must use solid pipes in your code, but posting on this forum modifies them, so we can never tell if they're the correct solid pipe characters or not...

Jim

amazingm

5:09 pm on May 29, 2008 (gmt 0)

10+ Year Member



Hello Jim,

I am using solid pipes. I have tried: Options +FollowSymLinks -MultiViews

Options +FollowSymLinks and with nothing other than the rewrite code. The result is the same: no redirection, 404.

I add the code to my root (main domain) htaccess file and when I click a link leading to any of the 5 "old" articles, I get a 404 with no redirection. I have cleaned my browser cache before trying to visit the web address but I still get no redirection, just a 404.

These are my current htaccess rules before adding the post redirection rules:

Options All -Indexes

# ultimate hotlink protection
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?domain\. [NC]
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?feedburner\.com/mysite [NC]
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?feedburner\.com/mysite#2 [NC]
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ - [F,NC]
</ifModule>

#No www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
# enable PHP error logging
php_flag log_errors on
php_value error_log /myerrorlog
# prevent access to PHP error log
<Files php_error.log>
Order allow,deny
Deny from all
Satisfy All
</Files>

jdMorgan

5:20 pm on May 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So the link to an old article looks exactly like this when you hover over it?
http://domain.com/post_name1

(If there's any additional URL-path info such as "feedburner" in that link, then it must be included in the RewriteRule pattern.)

Jim

amazingm

7:23 pm on May 29, 2008 (gmt 0)

10+ Year Member



They look like this:

[domain.com...]
[domain.com...]
[domain.com...]
[domain.com...]
[domain.com...]

At this point I'm not going to worry about the feedburner links, I just want these links redirecting.

Thanks for your help.

jdMorgan

8:41 pm on May 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Those don't exist as physical files do they? -- As index.php files in each of those directories, for example?

It looks like you've got some code above this .htaccess file -- meaning in httpd.conf or conf.d or another server config file that "maps" those URLs to files or scripts. If so, then the .htaccess code will never be invoked.

Jim

amazingm

9:24 pm on May 29, 2008 (gmt 0)

10+ Year Member



Jim,

I decided to take a closer look from within my File Manager in DirectAdmin and I saw another htaccess file that must have been created when support set up my hosting. It's in the public_html folder above my domain not in my domain public_html (it's located in domain/filemanager/public_html).

The rule is as follows:


RewriteEngine On
RewriteCond %{REQUEST_URI} !^/~domain/domain.com(.*) [NC]
RewriteRule ^(.*)$ /~domain/domain.com/$1

I'm not sure what it means and if I should leave it alone. Could this be what's causing the problems?

The posts are wordpress posts and are located in a database, there are no static pages remaining in the root folder except for a new html page and files associated with it. There are no files associated with the blog remaining in the root folder, I moved everything (the entire wordpress folder) over to the subdomain and it's working properly but I can't get the "old" links to redirect.

I may just have to email my wehost and request their assistance with this problem.

Thank you for all your time and effort.

[edited by: jdMorgan at 11:29 pm (utc) on May 29, 2008]
[edit reason] Formatting [/edit]

jdMorgan

11:37 pm on May 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It means "If the requested URL does not start with "/~domain/domain.com", then add "/~domain/domain.com to the requested URL-path. It seems that they have defined DocumentRoot to point to that directory instead of the proper one (which would be where your code is currently located).

It also means that the set-up is rather "mickey-mouse" and I'd be looking for a new host...

Also, the RewriteCond pattern includes regex tokens that are only a waste of time (the trailing "(.*)" on the pattern is completely unnecessary). Given that you can get an almost-virtual-private-server for $14.95 a month these days, I don't see any reason to use a host that uses the method they're employing here... It's quite strange.

However, their code does not seem like it would divert requests away from your own .htaccess code, as long as your own code is located at /~domain/domain.com/.htaccess

Jim

amazingm

10:07 am on May 30, 2008 (gmt 0)

10+ Year Member



Thanks for your advice. I will begin to look around for a new host.

g1smd

9:57 pm on May 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



*** when I click a link leading to any of the 5 "old" articles, I get a 404 with no redirection. ***

You shouldn't have any links pointing to the old article URLs from anywhere within your own sites.

amazingm

10:46 pm on May 30, 2008 (gmt 0)

10+ Year Member



"You shouldn't have any links pointing to the old article URLs from anywhere within your own sites."

I don't. I have the links in a text file in my PC.