1

I have links that are in this format: http://www.EXAMPLE.com/index.php?page=pageid They are also available at: http://www.EXAMPLE.com/?page=pageid

How can I redirect the ones without the index.php filename to use the index.php part of the url?

I have other re-direct rules in my htaccess file, and they are working fine, I just don't know how to force the index.php part and include the query string as well.

Sherwin Flight
  • 2,345
  • 7
  • 34
  • 54

1 Answers1

4

Put the following rules in your .htaccess file in the root of your site

RewriteEngine On
RewriteBase /

#only for the root directory
RewriteCond %{REQUEST_URI} ^/$
#if the uri is not already index.php
RewriteCond %{REQUEST_URI} !^/index.php [NC]
RewriteRule ^$ /index.php    [R=301,L]

If there are still conflicts with your other rules, you can further limit this rule to just requests with a page= querystring param by adding the followind condition before the rewrite rule above

# to limit further to only the requests with a page= param
RewriteCond %{QUERY_STRING} ^([^&]+&)*page=.*$ [NC]
Ulrich Palha
  • 9,411
  • 3
  • 25
  • 31