<p>I fixed it by adding <code>rewrite ^/index.php/(.*) /$1 permanent;</code> to my server block. This will redirect all urls containing <code>index.php</code> and something after it to the contents after <code>index.php</code>.</p>

<p>E.g. <code>/index.php/about</code> will be permanently redirected to <code>/about</code>. Google knows that if something is permanently redirected its the same content and will only index the redirect.</p>

<p>There's one drawback though, because <code>index.php</code> is an actual file you can still access that. So you need to keep <code>Disallow: /index.php</code> into your <code>robots.txt</code> as well.</p>

CC BY-SA 4.0
2018-08-16T22:51:33.983Z
2018-08-16T22:51:33.983Z
wouterds
<p>For whatever reason <code>https://domain.com/index.php?p=path/to/whatever</code> and <code>https://domain.com/index.php/to/whatever</code> both still work and are not being redirected or rewritten to <code>https://domain.com/path/to/whatever/</code>.</p>

<p>We are enabling these in our CraftCMS configuration:</p>

<pre><code>'omitScriptNameInUrls' =&gt; true,
'usePathInfo' =&gt; true
</code></pre>

<p>But they have not rectified the issue. Does anyone have a solution to this? Here are the important parts of our current <code>Nginx.conf</code>. I appreciate any help I can get on this.</p>

<pre><code>location ~ /.well-known {
    allow all;
}

location / {
    try_files $uri $uri/ @rewrites;
}

location @rewrites {
    rewrite ^(.*) /index.php?p=$1 last;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

error_log  /var/log/nginx/error_craft_https.log error;

error_page 404 /index.php;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    include fastcgi_params;
}

location ~* (?:\.(?:bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$ {
    deny all;
}

location ~* \.(?:manifest|appcache|html?|json|xml)$ {
    try_files $uri /index.php?$query_string;
    expires -1;
    access_log /var/log/nginx/access.log;
}

location ~* \.(?:rss|atom)$ {
    try_files $uri /index.php?$query_string;
    expires 1h;
    add_header Cache-Control "public";
}

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|h$
    try_files $uri /index.php?$query_string;
    expires 1M;
    add_header Cache-Control "public";
}

location ~* \.(?:css|js)$ {
    try_files $uri /index.php?$query_string;
    expires 1y;
    add_header Cache-Control "public";
}

location ~* \.(?:ttf|ttc|otf|eot|woff)$ {
    try_files $uri /index.php?$query_string;
    expires 1M;
    add_header Cache-Control "public";
}
</code></pre>

CC BY-SA 3.0
2016-05-18T16:38:56.483Z
I've added Disallow: /index.php to my robots.txt to stop Google from indexing those pages. No one seems to have a solution to this, and this seems to be the next best thing.
danpaquette
CC BY-SA 4.0
2018-08-16T22:48:57.063Z
I had the same issue a few weeks ago, explained a bit [how I fixed it here](https://wouterdeschuyter.be/blog/get-rid-of-duplicate-index-php-urls-next-to-your-pretty-urls-using-a-simple-nginx-rewrite).
wouterds
<url><redirect><nginx><redirection>
Nginx: index.php URLs still being served alongside pretty URLs
# Nginx: index.php URLs still being served alongside pretty URLs

(Asked by: username_0 on 2016-05-17)

For whatever reason https://domain.com/index.php?p=path/to/whatever and https://domain.com/index.php/to/whatever both still work and are not being redirected or rewritten to https://domain.com/path/to/whatever/.
We are enabling these in our CraftCMS configuration:
'omitScriptNameInUrls' => true,
'usePathInfo' => true

But they have not rectified the issue. Does anyone have a solution to this? Here are the important parts of our current Nginx.conf. I appreciate any help I can get on this.
location ~ /.well-known {
    allow all;
}

location / {
    try_files $uri $uri/ @rewrites;
}

location @rewrites {
    rewrite ^(.*) /index.php?p=$1 last;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

error_log  /var/log/nginx/error_craft_https.log error;

error_page 404 /index.php;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    include fastcgi_params;
}

location ~* (?:\.(?:bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$ {
    deny all;
}

location ~* \.(?:manifest|appcache|html?|json|xml)$ {
    try_files $uri /index.php?$query_string;
    expires -1;
    access_log /var/log/nginx/access.log;
}

location ~* \.(?:rss|atom)$ {
    try_files $uri /index.php?$query_string;
    expires 1h;
    add_header Cache-Control "public";
}

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|h$
    try_files $uri /index.php?$query_string;
    expires 1M;
    add_header Cache-Control "public";
}

location ~* \.(?:css|js)$ {
    try_files $uri /index.php?$query_string;
    expires 1y;
    add_header Cache-Control "public";
}

location ~* \.(?:ttf|ttc|otf|eot|woff)$ {
    try_files $uri /index.php?$query_string;
    expires 1M;
    add_header Cache-Control "public";
}

**Tags:** url, redirect, nginx, redirection
> **Comments:**
> **username_0**: I've added Disallow: /index.php to my robots.txt to stop Google from indexing those pages. No one seems to have a solution to this, and this seems to be the next best thing.  
> **username_1**: I had the same issue a few weeks ago, explained a bit [how I fixed it here](https://wouterdeschuyter.be/blog/get-rid-of-duplicate-index-php-urls-next-to-your-pretty-urls-using-a-simple-nginx-rewrite).  

---

## 1 answers

### Answer by username_1 on 2018-08-16. Score: 2

I fixed it by adding `rewrite ^/index.php/(.*) /$1 permanent;` to my server block. This will redirect all urls containing `index.php` and something after it to the contents after `index.php`.

E.g. `/index.php/about` will be permanently redirected to `/about`. Google knows that if something is permanently redirected its the same content and will only index the redirect.

There's one drawback though, because `index.php` is an actual file you can still access that. So you need to keep `Disallow: /index.php` into your `robots.txt` as well.


---

