我在访问具有相同起始名称url的URL时遇到问题:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^sections?$ sections.php [NC,L]
RewriteRule ^sections/?$ sections.php [NC,L]
RewriteRule ^sections/([0-9]+)/([a-zA-Z-.]+)/view?$ view_sections.php?id=$1&name=$2 [NC,L]
RewriteRule ^sections/([0-9]+)/([a-zA-Z-.]+)/view/?$ view_sections.php?id=$1&name=$2 [NC,L]
前两个规则有效,但最后两个没有,它只是加载sections.php而不是视图sections.php。当我使用Wamp时,它可以工作,但是当我在线上传它不起作用。是因为php和apache的版本吗?
My Wamp版本:
Apache版本:2.4.9
PHP版本:5.5.12
托管版本:
Apache版本:Apache / 2.2.27
PHP版本:5.6.14
如果问题是版本问题,那么可能的解决方案是什么使其在托管版本中工作?
答案 0 :(得分:1)
尝试这样,
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^sections?$ sections.php [NC]
RewriteRule ^sections/?$ sections.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^sections/([0-9]+)/([a-zA-Z-.]+)/view?$ view_sections.php?id=$1&name=$2 [QSA,NC]
RewriteRule ^sections/([0-9]+)/([a-zA-Z-.]+)/view/?$ view_sections.php?id=$1&name=$2 [QSA,NC,L]