【发布时间】:2015-01-27 16:08:49
【问题描述】:
我的网站上有一个页面动态生成,根据cityf 参数列出所有网点,下面是重写规则,将其转换为对 SEO 友好的 URL,它运行良好。
RewriteRule ^([^/.]+)/?$ /cityres?cityf=$1 [L]
我的网站上有一个博客页面,.htaccess 如下所示用于转换 SEO 友好 URL (http://example.com/title-of-blog)
RewriteRule ^([^/.]+)/?$ /blogdetail?prmn=$1 [L]
现在我面临的问题是,当有人访问 blog 页面时,链接 http://example.com/title-of-blog 而不是在页面上显示博客详细信息,而是显示我的错误消息 No outlets near title-of-blog。
我遇到了 Apache 无法识别何时重写 cityres 页面以及何时重写 blogdetail 页面的问题。
有人建议Make sure that each rule has a common prefix (e.g. /blog/page1 and /news/page2).,但我没听懂。
这里有什么建议吗?
编辑:
整个htaccess如下
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index
RewriteRule ^index\.php$ / [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# remove .php from URL
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
# remove .html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)\.html$ /$1 [L,R=301]
ErrorDocument 404 /error-page
ErrorDocument 403 /error-page
RewriteRule ^food-([^-]*)-([^-]*)\.html$ /pdetail?res_id=$1&location=$2 [L]
RewriteRule ^foodies-([^-]*)-([^-]*)$ /pdetail_new?res_id=$1&location=$2 [L]
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /pdetail_ne?location=$1&res_id=$2&name=$3 [L]
RewriteRule ^blog/([^/.]+)/?$ /blogdetail_fm?prmn=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !cityres
RewriteRule ^([^/.]+)/?$ /cityres?cityf=$1 [L]
【问题讨论】:
标签: .htaccess mod-rewrite url-rewriting