Last rule in mod_rewrite returns 404 even though page exists
I have the followin开发者_运维知识库g in my .htacccess file:
RewriteBase /
ErrorDocument 404 /404.php
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^news/([a-zA-Z]+)/([0-9]+)-([a-zA-Z]+) /news/view-article.php?category=$1&id=$2&title=$3 [NC]
RewriteRule ^news/most-viewed/([a-zA-Z]+)/([0-9]+)-([a-zA-Z]+) /news/view-article.php?category=$1&id=$2&title=$3 [NC]
RewriteRule ^news/categories/([a-zA-Z]+) /news/categories/view-category.php?category=$1 [NC]
Everything works apart from the last rule. I have checked that all the pages exist, the newly added rule follows the same structure as the rules above which work, confused.
Do the variables need changing? Am I missing some code?
RESOLVED:
RewriteBase /
ErrorDocument 404 /404.php
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^news/categories/?$ /news/categories.php [NC]
RewriteRule ^news/most-viewed/?$ /news/most-viewed.php [NC]
RewriteRule ^news/categories/([a-zA-Z]+)/?$ /news/view-category.php?category=$1 [NC]
RewriteRule ^news/categories/([a-zA-Z]+)/([0-9]+)-([a-zA-Z]+) /news/view-article.php?category=$1&id=$2&title=$3 [NC]
I was missing the $ on the end.
Try this, and let me know if that works
RewriteBase /
ErrorDocument 404 /404.php
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^news/([a-zA-Z]+)/([0-9]+)-([a-zA-Z]+)/?$ /news/view-article.php?category=$1&id=$2&title=$3 [NC,L]
RewriteRule ^news/most\-viewed/([a-zA-Z]+)/([0-9]+)-([a-zA-Z]+)/?$ /news/view-article.php?category=$1&id=$2&title=$3 [NC,L]
RewriteRule ^news/categories/([a-zA-Z]+)/?$ /news/categories/view-category.php?category=$1 [NC,L]
精彩评论