seo - .htaccess conditional statement -


i want rewrite urls more seo urls using wildcard sub-domains , unable write htaccess conditions , hoping it.

i have url:

http://learntipsandtricks.com/blog/c/magento

i want rewrite as:

http://magento.learntipsandtricks.com/

change pagination link:

http://learntipsandtricks.com/blog/92/magento/3

to:

http://magento.learntipsandtricks.com/p-92-3

finally change article url:

http://learntipsandtricks.com/blog/magento/114/magento-index-management-cannot-initialize-the-indexer-process

to:

http://magento.learntipsandtricks.com/114-magento-index-management-cannot-initialize-the-indexer-process

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.

from rewritecond directive

  • 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

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -