繁体   English   中英

RewriteRule - 删除参数键并将值保留在地址栏中

[英]RewriteRule - remove params keys and keep values in address bar

RewriteEngine ON    
RewriteRule ^video$ video.php [L] 

上面的行有效
example.com/video被解释为example.com/video.php

现在我需要example.com/video?id=5&s=lorem-ipsum
解释为example.com/video/5/lorem-ipsum - 反之亦然

RewriteCond %{THE_REQUEST} video?id=([^\s&]+)&s=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [R=301,L]
RewriteRule ^([\w-]+)/([\w-]+)/?$ video?id=$1&s=$2 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ video?/$1/$2 [L,QSA]  

不起作用 - 在两个方向上
请帮助

根据您显示的尝试,请尝试遵循 .htaccess 规则文件。 这些规则假设你想无限地重写 index.php 你可以根据你的要求在第二组规则中更改 php 文件名。

确保在测试您的 URL 之前清除您的浏览器缓存。

RewriteEngine ON
##External redirect Rules from here..
##Redirect 301 to example.com/video/5/lorem-ipsum from example.com/video?id=5&s=lorem-ipsum
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} \s/(video)\?id=([^&]*)&s=(\S+)\s [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]

##Internal rewrite for example.com/video?id=5&s=lorem-ipsum
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^video/([^/]*)/(.*)/?$ index.php?id=$1&s=$2 [QSA,NC,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM