zeemz
zeemz

Reputation: 375

Mod rewrite wildcard subdomain redirection issue

The problem i am facing is that i have a wild card domain where by i want to redirect all subdomain to a particular url i.e.

http://subdomain.domain.com --> http://www.domain.com/pagination.php?id=subdomain&page=1

similarly if

http://subdomain.domain.com/page-2 --> http://www.domain.com/pagination.php?id=subdomain&page=2

and if product id is given i.e.

http://subdomain.domain.com/some_product_name-123 --> http://www.domain.com/productview.php?id=123

My htaccess file is

RewriteCond %{http_host} .
RewriteCond %{http_host} !^www.pricesinpakistan.com.pk [NC]
RewriteCond %{http_host} ^([^.]+)\.pricesinpakistan.com.pk [NC]
RewriteRule page-^([^/]*)$ pagination.php?id=%1&page=$2 [L]
RewriteRule ^(.*)$ pagination.php?id=%1&page=1 [L]

The above rule is not catering the page rule all redirects are done on last rule with empty string as id.

Upvotes: 2

Views: 94

Answers (1)

anubhava
anubhava

Reputation: 784868

  • RewriteCond is only applicable to the next RewriteRule.
  • You cannot use anchor ^ in the middle of regex pattern.
  • To match landing page you need to use ^$ as URI pattern.

Use this rule instead:

RewriteCond %{http_host} !^www\.pricesinpakistan\.com\.pk$ [NC]
RewriteCond %{http_host} ^([^.]+)\.pricesinpakistan\.com\.pk$ [NC]
RewriteRule ^page-(\d+)/?$ pagination.php?id=%1&page=$1 [NC,L,QSA]

RewriteCond %{http_host} !^www\.pricesinpakistan\.com\.pk$ [NC]
RewriteCond %{http_host} ^([^.]+)\.pricesinpakistan\.com\.pk$ [NC]
RewriteRule ^$ pagination.php?id=%1&page=1 [L,QSA]

RewriteCond %{http_host} !^www\.pricesinpakistan\.com\.pk$ [NC]
RewriteCond %{http_host} ^([^.]+)\.pricesinpakistan\.com\.pk$ [NC]
RewriteRule ^(\w+)-(\d+)/?$ productview.php?catname=%1&productname=$1&productid=$2 [NC,L,QSA]

Upvotes: 1

Related Questions