douye5949
2014-01-20 07:44
浏览 75
已采纳

Htaccess重定向以匹配格式在所有URL中添加字符串

Pl advise

Incorrect URL

     www.abc.com/index.php?option=com_usedtoy&view=category&limitstart=495
     www.abc.com/index.php?option=com_usedtoy&view=category&limitstart=510
     www.abc.com/index.php?option=com_usedtoy&view=category&limitstart=525

Correct URL

     www.abc.com/index.php?option=com_usedtoy&view=category&Itemid=2&limitstart=495
     www.abc.com/index.php?option=com_usedtoy&view=category&Itemid=2&limitstart=510
     www.abc.com/index.php?option=com_usedtoy&view=category&Itemid=2&limitstart=525

How to add Itemid=2 in all url which match incorrect url format of usedtoy - which has Itemid missing

Edit After using the htaccess code

New result is

     www.abc.com/index.php?Itemid=2&option=com_usedtoy&view=category&limitstart=90
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongqian9567 2014-01-20 08:03
    已采纳

    put this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} (^|&)option=com_usedtoy(&|$) [NC]
    RewriteCond %{QUERY_STRING} !(^|&)Itemid=2(&|$) [NC]
    RewriteRule ^index\.php$ %{REQUEST_URI}/%{QUERY_STRING} [L,NC]
    
    RewriteRule ^(index\.php)/(option=com_usedtoy&view=category)&((?!Itemid=2&).+)$ /$1?$2&Itemid=2&$3 [L,NC,R=301]
    
    打赏 评论

相关推荐 更多相似问题