删除键并仅保留 url 参数中的值
remove keys and keep only values from url params
真实url - subdomain.example.com?id=3&s=lorem-ipsum
想要 - subdomain.example.com/3/lorem-ipsum
这是我的尝试:
RewriteEngine ON
RewriteCond %{THE_REQUEST} \?id=([^&]*)&s=([^\s&]*) [NC]
RewriteRule ^ /%1/%2? [R=301,L]
结果 - 想要 url 存在,但浏览器显示 404 错误 - 未找到
请帮忙
您收到 404
错误,因为重定向的 URL subdomain.example.com/3/lorem-ipsum
在您的服务器上不存在。要解决此问题,您需要将此新 URL 格式映射到其原始位置 subdomain.example.com?id=3&s=lorem-ipsum
.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \?id=([^&]*)&s=([^\s&]*) [NC]
RewriteRule ^ /%1/%2? [R=301,L]
#map new URL to the old one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/(.+)$ /?id=&s= [L]
真实url - subdomain.example.com?id=3&s=lorem-ipsum
想要 - subdomain.example.com/3/lorem-ipsum
这是我的尝试:
RewriteEngine ON
RewriteCond %{THE_REQUEST} \?id=([^&]*)&s=([^\s&]*) [NC]
RewriteRule ^ /%1/%2? [R=301,L]
结果 - 想要 url 存在,但浏览器显示 404 错误 - 未找到
请帮忙
您收到 404
错误,因为重定向的 URL subdomain.example.com/3/lorem-ipsum
在您的服务器上不存在。要解决此问题,您需要将此新 URL 格式映射到其原始位置 subdomain.example.com?id=3&s=lorem-ipsum
.
RewriteEngine ON
RewriteCond %{THE_REQUEST} \?id=([^&]*)&s=([^\s&]*) [NC]
RewriteRule ^ /%1/%2? [R=301,L]
#map new URL to the old one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/(.+)$ /?id=&s= [L]