seo - .htaccess conditional statement -
i want rewrite urls more seo urls using wildcard sub-domains , unable write htaccess conditions , hoping it.
i have url:
i want rewrite as:
change pagination link:
to:
finally change article url:
to:
i wrote this:
rewritecond %{http_host} !^www\.(.+)$ [nc] rewritecond %{http_host} (.+)\.learntipsandtricks\.com\/p\-(\d+)\-(d+) [nc] rewriterule ^(.*)$ http://learntipsandtricks.com/blog/%2/%1/%3/$1 [p] rewritecond %{http_host} !^www\.(.+)$ [nc] rewritecond %{http_host} (.+)\.learntipsandtricks\.com\/(\d+)\-(.*) [nc] rewriterule ^(.*)$ http://learntipsandtricks.com/blog/%1/%2/%3/$1 [p] rewritecond %{http_host} !^www\.(.+)$ [nc] rewritecond %{http_host} (.+)\.learntipsandtricks\.com [nc] rewriterule ^(.*)$ http://learntipsandtricks.com/blog/c/%1/$1 [p] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewritecond %{request_filename} !-l rewriterule ^(.*)$ index.php/$1 [l]
the above code doesn't work. possible using if else in htaccess check types of urls , rewrite accordingly?
edit:
rewritecond %{http_host} !^www\.(.+)$ [nc] rewritecond %{http_host} (.+)\.learntipsandtricks\.com [nc] rewritecond %{request_uri} ^/p-(\d+)-(\d+)$ [nc] rewriterule ^(.*)$ http://learntipsandtricks.com/blog/%1/[first part of sub-domain]/%2/$1 [p]
how can first part of sub-domain here.
thank you.
http_host
doesn't include url-path. if want match against url-path, use request_uri
instead
rewritecond %{request_uri} ^/p-(\d+)-(\d+)$
for example.
- rewritecond backreferences: these backreferences of form %n (0 <= n <= 9). %1 %9 provide access grouped parts (again, in parentheses) of pattern, from last matched rewritecond in current set of conditions. %0 provides access whole string matched pattern.
therefore, if want capture both domain , url-path components, must combine http_host
, request_uri
in 1 rewritecond
rewritecond %{http_host} !^www\.(.+)$ [nc] rewritecond %{http_host} (.+)\.learntipsandtricks\.com [nc] rewritecond %{http_host}%{request_uri} ^(.+)\.learntipsandtricks\.com/p-(\d+)-(\d+)$ [nc] rewriterule ^(.*)$ http://learntipsandtricks.com/blog/%2/%1/%3/$1 [p]
Comments
Post a Comment