Question

I use the following rules to rewrite a subdomain call to a page in the root of the website:

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]

RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9/_.-]+)\.domain\.com$ [NC]

RewriteRule .? headlines.php?url=%1 [L,QSA]

This works fine. I use this for a rss - news related website. For example: http://economy.headlines.com will internally look at http://www.headlines.com/headlines.php?url=economy

I also want to link to the news items in the following way: economy.headlines.com/news/title/id

How do i do this ? Because every time the first rules are "fired". Even if i make other rules with the [L] flag the other rules are fired and nothing happened.

How can i combine the rules above with new rules which also look at files in the root of the site but with parameters in the url ?

Was it helpful?

Solution

You should be able to combine both if you evaluate the path component of the request you rewrite:

Rewriteengine on
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9/_.-]+).domain.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ headlines.php?url=%1&category=$1&title=$2&id=$3 [L,QSA]

Probably you have to do some fine tuning, but I think you get the idea: the first argument of the RewriteRule is a regular expression that splits the request path into its components. Those can be referred to using the $1 and $2 notation you can see towards the end of the rule.


Edit: added the category parameter to the RewriteRule as discussed in the comments below.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top