Ruchika
Ruchika

Reputation: 515

htaccess redirect for redirecting all url with page to index.php

I need advise on to 301 permanent redirect using htaccess all pages having ?page=9 with index.php

Can anyone guide on how to achieve desired

For example -1

http://www.example.com/?page=9&option=com_news&view=list&Itemid=100&limitstart=840

to

http://www.example.com/index.php&option=com_news&view=list&Itemid=100&limitstart=840

or say for example 2

http://www.example.com/?page=17&option=com_news&view=list&Itemid=100

to

http://www.example.com/index.php&option=com_news&view=list&Itemid=100

Edit Used

RewriteEngine on

RewriteCond %{THE_REQUEST} \?page=.+&(.+)\sHTTP [NC]
RewriteRule ^ /index.php&%1? [L,R=301]

But it dint worked as output is

http://www.example.com/index.php&limitstart=840

Upvotes: 0

Views: 267

Answers (2)

CD001
CD001

Reputation: 8482

Assuming you actually want /index.php?option=... rather than /index.php&option=... - just matching on the querystring:

RewriteEngine On
RewriteCond %{QUERY_STRING} page=[^&]+&(.*) [NC]
RewriteRule .* /index.php?%1 [L,R,QSD]

However if you really do want /index.php&option=... replace the RewriteRule with:

RewriteRule .* /index.php&%1 [L,R,QSD]


Note: either way, this may not work as expected if page is not the first paramter


If your Apache version is older than 2.4 replace the RewriteRule with:

RewriteRule .* /index.php?%1? [L,R]

The [QSD] flag was only introduced with 2.4 - shouldn't be necessary anyway since the entire querystring is being matched.

Upvotes: 2

Amit Verma
Amit Verma

Reputation: 41249

You can use this :

RewriteEngine on

RewriteCond %{THE_REQUEST} \?page=.+&(.+)\sHTTP [NC]
RewriteRule ^ /index.php&%1? [L,R=301]

Upvotes: 1

Related Questions