开发者

mod_rewrite for multiple requests not working

开发者 https://www.devze.com 2023-04-13 03:51 出处:网络
Perhaps someone can help me with this before I go completely crazy with it. I have a site with two urls which I want to redirect.

Perhaps someone can help me with this before I go completely crazy with it. I have a site with two urls which I want to redirect.

I want all traffic except the gallery pages to go to index.php.

This is my htaccess:

php_flag magic_quotes_gpc Off

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]


RewriteRule ^(.*)$ /index.php?/$1

RewriteRule ^gallery(/((([a-zA-Z0-9-]+)(/(\d+))?)/?)?)?$ gallery.php?groupId=$4&showpage=$6 [NC,QSA,L]

This works except for one part. The rewrite rule for the gallery is not fully working. It is sending through the groupId开发者_运维百科 to the gallery.php script but I am not getting through the showpage argument. In fact when the showpage is included in the url I get a 404. So for instance.

These work and are handled correctly by the rewrite rule

gallery

gallery/

gallery/mygroup

gallery/mygroup/

This does not work and throws 404's.

gallery/mygroup/2

Nothing I do seems to fix this and I would appreciate your help on this. If I set the showpage. The gallery script works if I feed it the old

gallery.php?groupId=mygroup&showpage=2

so I am sure the htaccess rule is not catching the url.

Thanks in advance.


Your regex seems a little over-the-top. Use two simpler rewrite rules instead:

RewriteRule ^gallery/([a-zA-Z0-9-]+)/?$ gallery.php?groupId=$1 [NC,QSA,L]
RewriteRule ^gallery/([a-zA-Z0-9-]+)/(\d+)/?$ gallery.php?groupId=$1&showpage=$2 [NC,QSA,L]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号