mardi 20 février 2018

Laravel: Redirect url of type `user.php?id=3`

I want to support old urls after switching to Laravel.

Since its not allowed to use a dot . in the routes, I am tryting to redirect user.php?id=3 to /user/3 in the public/.htaccess file.

I tried

  RewriteCond %{QUERY_STRING} id=(.*)
  RewriteRule ^user\.php$ /user/$1 

but its not working. The RewriteRule is ignored. Any suggestions why it is ignored?

This is my full Laravel .htaccess:

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

    RewriteEngine On

    RewriteCond %{QUERY_STRING} id=(.*)
    RewriteRule ^user\.php$ /user/$1

    # Now, rewrite any request to the wrong domain to use www.
    # [NC] is a case-insensitive match
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    RewriteCond %{HTTPS} off
    # First rewrite to HTTPS:
    # Don't put www. here. If it is already there it will be included, if not
    # the subsequent rule will catch it.
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

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

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire