htaccess - 漂亮 url 有多个变量
htaccess - pretty url with multiple variables
<a href="sky.php?c=something&id=9&s=anything">sky</a>
something, 9, anything
是变量
在地址栏中我想看到这个:
...host/something/9/anything
所以 - 根本没有 sky.php
反向规则 - 从漂亮到丑陋 - 已解决 - 但如果您有任何通知 - 请执行:
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /sky.php?c=&id=&s= [L]
使用您显示的示例,请尝试执行以下操作。这考虑到您想在浏览器中点击 URL,例如:http://localhost:80/sky.php?c=something&id=9&s=anything
,应该在此处重定向到 http://localhost:80/something/9/anything
。
请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine ON
##This rule handles to change from non-friendly URL to friendly URL in browser.
RewriteCond %{THE_REQUEST} \s/(?:[^.]*)\.php\?c=([^&]*)&id=([^&]*)&s=([^\s&]*) [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]
##This rule internally rewrites friendly url to non-friendly url.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ sky.php?c=&id=&s= [L]
<a href="sky.php?c=something&id=9&s=anything">sky</a>
something, 9, anything
是变量
在地址栏中我想看到这个:
...host/something/9/anything
所以 - 根本没有 sky.php
反向规则 - 从漂亮到丑陋 - 已解决 - 但如果您有任何通知 - 请执行:
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /sky.php?c=&id=&s= [L]
使用您显示的示例,请尝试执行以下操作。这考虑到您想在浏览器中点击 URL,例如:http://localhost:80/sky.php?c=something&id=9&s=anything
,应该在此处重定向到 http://localhost:80/something/9/anything
。
请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine ON
##This rule handles to change from non-friendly URL to friendly URL in browser.
RewriteCond %{THE_REQUEST} \s/(?:[^.]*)\.php\?c=([^&]*)&id=([^&]*)&s=([^\s&]*) [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]
##This rule internally rewrites friendly url to non-friendly url.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ sky.php?c=&id=&s= [L]