我试图让我的网址看起来像这样:
http://example.com/photo-album-detail/jan-2016
目前看起来像是:http://example.com/photo-album-detail/?album=jan-2016
我怎么能实现这个目标?
我现在拥有的是:
RewriteRule ^photo-album-detail/* photo-album-detail/?album=$1
但这似乎并没有解决我的问题
答案 0 :(得分:0)
您的重写规则不完整 - 您需要捕获相册值:
arr.sort(function(a, b) {
return num - 1 * a.dezibel + num - 1 * b.dezibel
})
在htaccess的顶部添加此项,之前使用RewriteRule ^photo-album-detail/(.+)$ photo-album-detail/?album=$1 [L]
。
答案 1 :(得分:0)
我认为您并不了解mod_rewrite的工作原理。
您在此规则中匹配的网址
RewriteRule ^photo-album-detail/(.+) photo-album-detail/?album=$1 [L]
这种类型的网址是http://example.com/photo-album-detail/jan-2016
,因为这是您匹配的模式。
如果您想基于使用此类型的网址http://example.com/photo-album-detail/?album=jan-2016
进行重定向,则需要在query string
或the request
上进行匹配。
这些是您需要的组合规则。
RewriteEngine On
#if request is a real file or directory do nothing
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
#redirect the old query string URL to the rewritten URL
RewriteCond %{THE_REQUEST} ^GET\ /photo-album-detail/\?album=([^&\s]+)
RewriteRule ^ /photo-album-detail/%1? [R=302,L]
#internally rewrite pretty URL to querystring
RewriteRule ^photo-album-detail/(.+) /photo-album-detail/?album=$1 [L]
让我知道这对你有用。