2

I would like to modify my htaccess to :

  1. Redirect all *.php calls to app.php (SEO call to keep ranking from migration)
  2. Avoid redirection loop excluding app.php for rewrite rule above.

I ended up with this :

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI} !app\.php$
    RewriteRule ^(.*)\.php?$ /app.php/ [R=301,L]

   [...]

</IfModule>

But this produces a 404 on test url like http://example.com/sqdlkqjsdlsqk.php

What's wrong in here?

Regards,

2 Answers 2

1

You should be using this rule without trailing slash after app.php:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/app\.php$ [NC]
RewriteRule ^(.+)\.php$ /app.php [R=301,L,NC,NE]

Make sure to clear browser cache before testing this change.

Sign up to request clarification or add additional context in comments.

Comments

1

Check this out. Make sure to clear your cache.

DirectoryIndex app.php

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteEngine On
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        # When mod_rewrite is not available, we instruct a temporary redirect of
        # the start page to the front controller explicitly so that the website
        # and the generated links can still be used.
        RedirectMatch 302 ^/$ /app.php/
        # RedirectTemp cannot be used instead
    </IfModule>
</IfModule>

1 Comment

Thank you, this worked as well but was a bit overkill for my needs. +1 for mod_rewrite disabled handling

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.