I have two cases, it is very hard for me to separate them. I see them as redirection -problem.

# 1.    I want to redirect all .*/feeds to mySite.com/feeds showing
#       the content of mySite.com/Layout/feeds.html but keeping the 
#       url intact as mySite.com/feeds
# 2.    I want to redirect all non-existent art.mySite.com/.* to
#       art.mySite.com
RewriteEngine On

#REDIRECT pages that are not specifically redirected 
# Alert! I am not sure whether this intervenes, sites not
# of that Regex -match are directed to the parametered url.
RewriteCond %{HTTP_HOST} !^www\.mySite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mySite.com/$1 [R=301,L]

Case 1

#1. BROKEN: it directs mySite.com/feeds to mySite.com according to the 
#       above notice, apparently?!
#       mySite.com/feeds and feeds.mySite.com must show the 
#       content on mh.com/Layouts/feeds.html but the url must remain
RewriteCond %{HTTP_HOST} ^www\.mySite\.com/feeds$ [NC]
RewriteRule ^(.*)$ http://www.mySite.com/Layouts/feeds.html [R=301,L]
RewriteCond %{HTTP_HOST} ^feeds\.mySite\.com/$1 [NC]
RewriteRule ^(.*)$ http://www.mySite.com/Layouts/feeds.html [R=301,L]

Case 2

# art.mySite.com/feeds directs to Blogger -site...BAD. It is because
# art.mySite.com displays the Blogger content but it tries do display
# Blogger content also in non-blogger urls such as art.mySite.com/aoeu
# not doing anything or?
#RewriteCond %{HTTP_HOST} ^art\.mySite\.com/.*$ [NC]
#RewriteRule ^(.*)$ http://friend.blogspot.com/$1 [R]

# WORKS i.e. directs the art.mySite.com to the Blogger and keeps the domain
# but this does not handle the non-existing cases trying to do with (2)
RewriteCond %{HTTP_HOST} ^art\.mySite\.com
RewriteRule ^(.*)$ http://friend.blogspot.com/$1 [R]

1 Answer 1


Remember that the order of rewrite rules is very important as rule processing stops once a rule is matched.

For example, if you first rewrite everything that is not http://www.mysite.com, then you will never match http://something.mysite.com later on because the host has already been rewritten. In this case, you would want to rewrite your feed url's first, and rewrite your traffic to http://www.mysite.com in a rule later on.

Rewrite rules can be extremely tedious and cryptic and will just take some time to figure out (it is well worth the effort!).

To start, enable rewrite logging so you can see what is happening:

RewriteEngine On
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 9

RewriteLogLevel is a 0-9 value, with 9 being debug. Be sure to turn this off on production:

### I just comment them out when not in use ###
#RewriteEngine On
#RewriteLog "/var/log/apache2/rewrite.log"
#RewriteLogLevel 9

You will need to reload your apache once you have enabled or disabled logging: /etc/init.d/apache2 reload for example.

I then usually open a new terminal and tail -f /var/log/apache2/rewrite.log while I am debugging.

Of course, never play with rewrites on a production system as it is extremely easy to bring things to a halt ;)

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.