URL Rewriting with multiple parameters without changing the URL

I want to rewrite my url

From:

https://example.com/fr/transporter/transporterPublicProfile.php?profil=1927&token=xnbjfgh4534534534dgfsdsd4

To:

https://example.com/fr/profil-des-transporteurs/1927/xnbjfgh4534534534dgfsdsd4

When the user visits this url:

https://example.com/fr/transporter/transporterPublicProfile.php?profil=1927&token=xnbjfgh4534534534dgfsdsd4

It should look like this:

https://example.com/fr/profil-des-transporteurs/1927/xnbjfgh4534534534dgfsdsd4

And if the user visits this url:

https://example.com/fr/profil-des-transporteurs/1927/xnbjfgh4534534534dgfsdsd4

He must remain as he is.

I've tried so far:

    Options +FollowSymLinks -MultiViews
    RewriteEngine On

    RewriteBase /fr/
    # external redirect from actual URL to pretty one
    RewriteCond %{THE_REQUEST} /fr/transporter/transporterPublicProfile\.php\?profil=([^\s&]+) [NC]
    RewriteRule ^ fr/profil-des-transporteurs/%1? [R=302,L,NE]

    # internal forward from pretty URL to actual one
    RewriteRule ^profil-des-transporteurs/([^/.]+)/?(.*)$ transporter/transporterPublicProfile.php?profil=$1&token=$2 [L,QSA,NC]


    RewriteBase /

    #RewriteRule    ^/fr/shipper/(.*)$ https://example.com/fr/$1 [L,R=301]

    #RewriteRule    ^login.php https://example.com/fr/shipper/login.php [L]
    RewriteRule ^index\.html /index\.php......................

      

The problem above .htaccess - this works fine with one parameter ie profil , But when I get the token in the url, it doesn't work.

What would be the correct .htaccess code for this scenario?

+3


source to share


1 answer


You need to have a new set of rules for the new parameter:



Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /fr/

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /fr/transporter/transporterPublicProfile\.php\?profil=([^\s&]+)&token=([^\s&]+) [NC]
RewriteRule ^ profil-des-transporteurs/%1/%2? [R=302,L,NE]

RewriteCond %{THE_REQUEST} /fr/transporter/transporterPublicProfile\.php\?profil=([^\s&]+) [NC]
RewriteRule ^ profil-des-transporteurs/%1? [R=302,L,NE]

# internal forward from pretty URL to actual one
RewriteRule ^profil-des-transporteurs/([^/.]+)/([^/]+)/?$ transporter/transporterPublicProfile.php?profil=$1&token=$2 [L,QSA,NC]

RewriteRule ^profil-des-transporteurs/([^/.]+)/?$ transporter/transporterPublicProfile.php?profil=$1 [L,QSA,NC]

RewriteRule ^index\.html /index\.php [L]

      

+3


source







All Articles