我有以下.htaccess文件:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^mangas/([^/]+)/([^/]+)/$ - [F,L]
RewriteRule ^mangas/([^/]+)/$ - [F,L]
RewriteRule ^mangas(/?)$ - [F,L]
RewriteRule ^([^/.]+)/([^/.]+)/([0-9]+)(/?)$ index.php?manga=$1&chapter=$2&page=$3 [L]
RewriteRule ^([^/.]+)/([^/.]+)(/?)$ index.php?manga=$1&chapter=$2 [L]
RewriteRule ^([^/.]+)(/?)$ index.php?manga=$1 [L]
但是当您转到以下链接时会发生什么:/manga/name_of_manga
它给出了404未找到的错误。是否htaccess文件没有将index.php?manga=$1
重写为:/manga/name_of_manga
?
基本上,index.php?manga=$1
形式的任何内容都只会转换为/manga/name_of_manga
,它仍应显示内容。如果我直接使用index.php方法,它可以正常工作。
例如,这些工作:
http://neoblizz.net/manga/?manga=Tower%20of%20God
http://neoblizz.net/manga/index.php?manga=Tower%20of%20God
这些不是:
http://neoblizz.net/manga/Tower_of_God/
http://neoblizz.net/manga/Tower%20of%20God/
154.20.109.65 - - [03/Jul/2014:18:28:50 -0400] "GET /manga/ HTTP/1.1" 500 - neoblizz.net "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" "-"
154.20.109.65 - - [03/Jul/2014:18:28:51 -0400] "GET /manga/ HTTP/1.1" 500 - neoblizz.net "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" "-"
154.20.109.65 - - [03/Jul/2014:18:28:52 -0400] "GET /manga/ HTTP/1.1" 500 - neoblizz.net "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" "-"
154.20.109.65 - - [03/Jul/2014:18:28:52 -0400] "GET /manga/ HTTP/1.1" 500 - neoblizz.net "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" "-"
答案 0 :(得分:0)
这样做:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /manga/
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^mangas/([^/]+)/([^/]+)/?$ - [F,L]
RewriteRule ^mangas/([^/]+)/?$ - [F,L]
RewriteRule ^mangas/?$ - [F,L]
RewriteRule ^([^/]+)/([^/]+)/([0-9]+)/?$ index.php?comic=$1&chapter=$2&page=$3 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?comic=$1&chapter=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?comic=$1 [L,QSA]