I discovered search engines found duplicate content on my domain due to URLs being output with index.php?p= and index.php in ADDITION to the clean URLs.

For example, I have:

  1. domain.com/index.php?p=about
  2. domain.com/index.php/about
  3. domain.com/about

And the first two requests with index.php?p= and index.php shouldn't exist. Only the last request with domain.com/about should exist.

While I found help removing index.php, some URLs continue to include ?p=.

So, now I still have:

  1. domain.com/?p=about
  2. domain.com/about

While all I want is:

  1. domain.com/about

Note: This is happening to several pages and blog entries throughout the site. Not only URLs directed to about.

How may I remove ?p= permanently from the remaining URLs?

Within .htaccess, I have:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Remove index.php
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !^/index\.php/admin\b [NC] # Don't mess with admin requests
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

Within craft/config/general.php, I have:

return array(
    '*' => array(

        'omitScriptNameInUrls' => true,
    ),
);
up vote 5 down vote accepted

Taken from this answer on Stack Overflow: .htaccess mod_rewrite: rewriting querystring to path

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Remove index.php
    RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
    RewriteCond %{REQUEST_URI} !^/index\.php/admin\b [NC] # Don't mess with admin requests
    RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

    # Remove ?p=
    RewriteCond %{THE_REQUEST} ^GET\ /\?(([^&\s]*&)*)p=([^&\s]+)&?([^\s]*)
    RewriteRule ^(.*)$ /%3?%1%4 [L,R=301]

    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

This not only reformats /?p=about as /about, but it also preserves other parts of the query string.

For example, /?p=about&tag=stuff and even /?tag=stuff&p=about both redirect to /about?tag=stuff.

  • If i use this then i cannot login to admin dashboard anymore.... Any idea? – Paulv12345 Aug 31 '17 at 8:57
  • If you are using a different url other than /admin to access your control panel, you will need to update line 6 above and replace "admin" with your custom control panel trigger. RewriteCond %{REQUEST_URI} !^/index\.php/your-custom-cp-trigger\b [NC] – Alex Roper Sep 1 '17 at 17:24

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.