gpt4 book ai didi

php - 在不更改 URL 的情况下使用多个参数重写 URL

转载 作者:搜寻专家 更新时间:2023-10-31 20:39:06 25 4
gpt4 key购买 nike

我想重写我的网址

来自:

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 中获得token 时,它不起作用。

对于这种情况,正确的 .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]

关于php - 在不更改 URL 的情况下使用多个参数重写 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27687523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com