Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index.php shown in url for cached pages #18

Open
julianchristmas opened this issue May 22, 2018 · 7 comments
Open

index.php shown in url for cached pages #18

julianchristmas opened this issue May 22, 2018 · 7 comments
Labels

Comments

@julianchristmas
Copy link

First of all, thanks for this great package.

index.php shown in url

I have tested it on our simple Laravel website and found a little quirk.
When visiting a cached page, the displayed url includes index.php
This is not beneficial for SEO and UX, therefore I would like to change it.

Have anyone else experienced this issue and found a work around?

Prior to installing this package, urls where in the form of https://app_url.com/route

After installation and visiting all package to warm the cache, the urls are now in the form of https://app_url.com/index.php/route

Outcommenting the recommended lines from .htaccess resolves the problem, but views are no longer served from cache.

Apache configuration

Apache running with PHP 7.2
The full .htaccess file is as follows

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Serve Cached Page If Available...
    RewriteCond %{REQUEST_URI} ^/?$
    RewriteCond %{DOCUMENT_ROOT}/page-cache/pc__index__pc.html -f
    RewriteRule .? page-cache/pc__index__pc.html [L]
    RewriteCond %{DOCUMENT_ROOT}/page-cache%{REQUEST_URI}.html -f
    RewriteRule . page-cache%{REQUEST_URI}.html [L]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

# BEGIN Expires-Headers
<IfModule mod_expires.c>
  <FilesMatch "\.(js|css)$">
    ExpiresActive On
    ExpiresDefault "access plus 4 weeks"
  </FilesMatch>
</IfModule>
# END Expires-Headers

# BEGIN Cache-Control-Headers
<ifmodule mod_headers.c>
  <filesmatch "(gif|ico|jpeg|jpe|jpg|svg|png|css|js)$">
    Header set Cache-Control "max-age=604800, public"
  </filesmatch>
</ifmodule>
# END Cache-Control-Headers
@gauravmak
Copy link

Yes, we faced the same issue.

The solution was to put the redirection code as per https://stackoverflow.com/a/21813759/3113599
It's for nginx though.

@sebastiandedeyne
Copy link

I have the same issue. Using nginx. Is this a configuration problem or something the package can solve?

@alexjoffroy
Copy link

Using Nginx, I fixed the issue in my site config (thanks to @gauravmak 's link).

if ($request_uri ~* "^(.*/)index\.php(\/?)(.*)") {
    return 301 $1$3;
}

@william1888
Copy link

Is there a recommended solution for apache?

@dieg0v
Copy link

dieg0v commented Apr 20, 2019

I think you can use a 301 redirect in apache, after "Serve Cached Page If Available" condition, maybe you have to delete the entire cache first, something like this:

RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html)(.*)\ HTTP
RewriteRule ^(.*)index\.(php|html)$ /$1 [R=301,L]

@rajeshtandukar
Copy link

Still index.php shown in url for cached pages with Laravel 5.5 ( Apache Server)
Any solution plz?

@bmpf
Copy link

bmpf commented May 9, 2022

For those who are using apache ,
Add this two line after RewriteEngine On in .htaccess

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

*clear the cache after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants