2016-01-06 83 views

回答

0

你重写规则,是不完整的 - 你需要捕捉专辑值:

RewriteRule ^photo-album-detail/(.+)$ photo-album-detail/?album=$1 [L] 

将此添加到您的htaccess的顶部,之前使用RewriteEngine on

+0

这似乎没有做任何事情:/ – Kazehaya

+0

你可以尝试更新的规则,看看它是否有帮助吗? – vard

+0

这是链接到的网址:http://example.com/photo-album-detail/?album=jan-2016它应该更改为http://example.com/photo-album-detail/jan-2016对?仍然没有工作:( – Kazehaya

0

我认为你不理解mod_rewrite是如何工作的。

您在此规则

RewriteRule ^photo-album-detail/(.+) photo-album-detail/?album=$1 [L] 

匹配对URL是这种类型的URL http://example.com/photo-album-detail/jan-2016的,因为这是你的匹配与模式。

如果您想要使用此类型的URL重定向http://example.com/photo-album-detail/?album=jan-2016那么您需要匹配query stringthe 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] 

让我知道这是如何适用于你。

+0

感谢您的帮助,但它似乎不工作:/ 它没有做任何事情,它看起来像 – Kazehaya

+0

您的.htaccess文件启用吗?您需要确保'AllowOverride All'设置在您的配置。 –