Forum Moderators: phranque
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.
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 Options +FollowSymLinks -MultiViews 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
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>
[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.
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
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
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]
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