使用友好URL中的额外参数在子目录中搜索页面(htaccess)

时间:2015-04-06 17:13:55

标签: php apache .htaccess mod-rewrite search

我的htaccess目前正在

# rewrite engine on and setting up base
RewriteEngine On
RewriteBase /leffa

# replace + with _
RewriteRule ^(.+)\+(.+)$ $1-$2 [R=301]

# external redirect from action URL to pretty one
RewriteCond %{THE_REQUEST} /index(?:\.php)?\?q=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]

# internal forward from pretty URL to actual URL
RewriteRule ^([^/.]+)/?$ index.php?q=$1 [L,QSA,NC]

当您点击任何电影标题时,会在here中产生正确的重写。但是,我还有一个额外的参数?kuvauksesta = 1当你从描述中搜索而不是标题时(我已经删除了复选框,因为它当前不起作用)。

如何使用搜索查询中的第二个参数进行此重写?手动输入http://www.rollemaa.org/leffa/pelottava?kuvauksesta=1确实有效,但使用复选框输入时,只需删除第二个参数,请尝试查看:http://www.rollemaa.org//leffa/index.php?q=pelottava&kuvauksesta=1

如何在网址中设置第二个参数,使其干净且可搜索?

1 个答案:

答案 0 :(得分:1)

这样做:

# rewrite engine on and setting up base
RewriteEngine On
RewriteBase /leffa/

# replace + with _
RewriteRule ^(.+?)\+(.+)$ $1-$2 [R=301,L,NE]

# external redirect from action URL to pretty one
RewriteCond %{THE_REQUEST} /index(?:\.php)?\?q=([^\s&]+)&(kuvauksesta)= [NC]
RewriteRule ^ %1/%2? [R=302,L,NE]

RewriteCond %{THE_REQUEST} /index(?:\.php)?\?q=([^\s&]+)\s [NC]
RewriteRule ^ %1? [R=302,L,NE]

# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# internal forward from pretty URL to actual URL (extra parameter)
RewriteRule ^([^/.]+)/([^/.]+)?$ index.php?q=$1&$2=1 [L,QSA]

# internal forward from pretty URL to actual URL
RewriteRule ^(.+)/?$ index.php?q=$1 [L,QSA]