Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am wanting to create redirect for urls using .htaccess

http://shows.example.com/showtitle/sitemap.xml

to map to my existing folder structure what is like

http://shows.example.com/sitemaps/sitemap_shows_showtitle_3day.xml

two variable the subdomain which can differ and the showtitle

so i wrote

RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$
RewriteCond %{REQUEST_URI} ^/([a-z]*)/sitemap.xml
RewriteRule ^(.*)$    http://%1.example.com/sitemaps/sitemap_%1_$1_3day.xml [L]

which redirects to

http://superstar.example.com/sitemaps/sitemap_superstar__3day.xml

Do i need to combine both RewriteCond into one to access both variables? Or can I get the variables from as they are?

share|improve this question
    
Where's this .htaccess file located? And what request is it handling? It doesn't add up for the $1 to be an empty string. –  Shane Madden Jul 29 '12 at 18:56
    
the .htaccess is located in the root directory, i'm just passing the example url through shows.example.com/showtitle/sitemap.xml –  bertsisterwanda Jul 30 '12 at 8:02

1 Answer 1

up vote 1 down vote accepted

Managed to get it working this way.

RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$
RewriteRule ^([a-z]*)/sitemap.xml http://%1.example.com/sitemaps/sitemap_%1_$1_3day.xml [L,R=302]
share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.