dongrenshi0889 2016-09-02 08:52
浏览 56
已采纳

htaccess Symfony2将所有* .php页面(但app.php)重定向到app.php

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条回答 默认 最新

  • dszsajhd237437 2016-09-02 08:54
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?