StormTrooper
StormTrooper

Reputation: 1573

URL Rewriting with multiple parameters without changing 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 ever a user visit this URL:

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

It should appear like this:

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

And if a user visit this URL:

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

Its should remain as it is.

What I have tried so far is:

    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 in above .htaccess is it works fine with one parameter i.e profil . But when I get token in URL, it doesnt work.

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

Upvotes: 3

Views: 856

Answers (1)

anubhava
anubhava

Reputation: 784898

You need to have new set of rules for 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]

Upvotes: 4

Related Questions