I want to rewrite my URL
From:
https://example.com/fr/transporter/transporterPublicProfile.php?profil=1927
To:
https://example.com/fr/profil-des-transporteurs/1927
When ever a user visit this URL:
https://example.com/fr/transporter/transporterPublicProfile.php?profil=1927
It should appear like this:
https://example.com/fr/profil-des-transporteurs/1927
And if a user visit this URL:
https://example.com/fr/profil-des-transporteurs/1927
Its should remain as it is.
What I have tried so far is:
RewriteRule ^profil-des-transporteurs/(.*)$ /fr/transporter/profil.php?oid=$1 [L]
It changes the URL as I want but the problem is that, the links on that page doesn't works properly. The page is using relative paths for images etc w.r.t new URL i.e:
https://example.com/fr/profil-des-transporteurs/
You can use this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+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 ^fr/profil-des-transporteurs/([^/.]+)/?$ fr/transporter/transporterPublicProfile.php?profile=$1 [L,QSA,NC]
Then for resolving relative links used for images/js/css paths you can add this in the <head>
section of your page's HTML:
<base href="/fr/transporter/" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With