简体   繁体   English

.htaccess无法正常工作

[英].htaccess doesn't work as expected

I'm quite newbie in mod_rewrite and trying to do 'friendly URL's' but there is some problem that I can't figured it out. 我是mod_rewrite的新手,正在尝试做“友好的URL”,但是有一些我无法弄清楚的问题。 So, I have categories and the url is 所以,我有类别,URL是

/pic.php?cat_id=1
After rewrite it I get this url

/pic/1

When category load there is 1 image and button 'Next'. 当类别加载时,有1张图片和“下一步”按钮。 When I click on 'Next' my URL is 当我点击“下一步”时,我的网址是

pic.php?cat_id=11&id=20
After rewrite
pic/1/2

And here Is the problem. 问题就在这里。 When I click 'Next' forn next image the page is refreshed, the image is sam and the url became 当我单击“下一步”时,下一张图片将刷新页面,该图片是sam,URL变为

pic/1/1/2

And after every 'Next' click put one more /1/ Here is the .htaccess that I use right now 在每次“下一步”之后,再放一个/1/这是我现在使用的.htaccess

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^pic/([0-9]+)(/([0-9]+))? pic.php?cat_id=$1&line[0]=$3 [L,QSA]
RewriteRule ^pic/([0-9]+)? pic.php?cat_id=$1 [L,QSA]

And here are both links 这是两个链接

<a href="pic/'. $res['cat_id'] .'"> <--- for selecting category
<a href="'.$cat_id.'/'.$line[0].'"> <--- next image in that category

And if I choose another category while I'm in some category my URL become 如果我在某个类别中选择其他类别,我的网址将变为

pic/1/2/pic/2/ <---put other category url next to the current category

What is wrong here? 怎么了

试试这个代码:

<a href="pic/'. $res['cat_id'] .'/"> <a href="../../pic/'.$cat_id.'/'.$line[0].'">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM