Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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 showing
#       the content of but keeping the 
#       url intact as
# 2.    I want to redirect all non-existent* to
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 ^(.*)$$1 [R=301,L]

Case 1

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

Case 2

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

# WORKS i.e. directs the 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 ^(.*)$$1 [R]
share|improve this question

migrated from Mar 3 '12 at 20:02

This question came from our site for system and network administrators.

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, then you will never match 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 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!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.