htaccess /index.php?u=xx&p=yy 至 /xx/yy/ URL 重写

发布于 2025-01-11 15:45:48 字数 316 浏览 0 评论 0原文

我想知道如何将网址 /index.php?u=xx&p=yy 更改为 /xx/yy/

index.php 将被删除,u 和 p 值将带有斜杠标记。

htaccess 代码:

RewriteCond %{THE_REQUEST} /index\.php[\s?/] [NC]
RewriteRule ^(.*?)index\.php(/.*)?/?$ /$1$2 [L,R=301,NC,NE]

我使用了上面的代码,但它只删除了index.php。其他保持不变。

I would like to know how to URL change /index.php?u=xx&p=yy to /xx/yy/.

index.php will be removed and u and p values become with a slash mark.

htaccess code:

RewriteCond %{THE_REQUEST} /index\.php[\s?/] [NC]
RewriteRule ^(.*?)index\.php(/.*)?/?$ /$1$2 [L,R=301,NC,NE]

I have used the above code but it only removes index.php. Others are remaining the same.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷了相思 2025-01-18 15:45:48

根据您显示的示例/尝试,请尝试遵循 htaccess 规则。在测试您的网址之前,请确保清除浏览器缓存。

另请确保您的 htaccess 规则文件和 index.php 文件位于同一目录中。

RewriteEngine ON
##External redirect rules as follows:
RewriteCond %{THE_REQUEST} \s/p/index\.php\?u=([^&]*)&p=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]

##Internal rewrite rules as follows:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(.*)/?$ index.php?u=$1&p=$2 [QSA,L]

With your shown samples/attempts, please try following htaccess rules. Please make sure to clear your browser cache before testing your URLs.

Also please make sure that your htaccess rules file and index.php files are in same directory.

RewriteEngine ON
##External redirect rules as follows:
RewriteCond %{THE_REQUEST} \s/p/index\.php\?u=([^&]*)&p=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]

##Internal rewrite rules as follows:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(.*)/?$ index.php?u=$1&p=$2 [QSA,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文