我想重写我的url
发件人:
https://example.com/fr/transporter/transporterPublicProfile.php?profil=1927&token=xnbjfgh4534534534dgfsdsd4
致:
https://example.com/fr/profil-des-transporteurs/1927/xnbjfgh4534534534dgfsdsd4
当用户访问此URL时:
https://example.com/fr/transporter/transporterPublicProfile.php?profil=1927&token=xnbjfgh4534534534dgfsdsd4
应该是这样的:
https://example.com/fr/profil-des-transporteurs/1927/xnbjfgh4534534534dgfsdsd4
如果用户访问此url:
https://example.com/fr/profil-des-transporteurs/1927/xnbjfgh4534534534dgfsdsd4
它应该保持原样。
到目前为止,我所尝试的是:

    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......................

上面的问题是,htaccess在一个参数profil下运行良好
是的。但当我在url中获得令牌时,它就不起作用了。
此方案的正确.htaccess代码是什么?

最佳答案

您需要为新参数设置新的规则集:

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]

10-06 02:29