Altervista论坛.htaccess重定向例外配置报500错误求助
问题根源与修复方案
你的500错误是因为RewriteCond里的正则语法写错了——你给不需要转义的普通文件名(比如maintenance、misc、getcomuni)加了多余的反斜杠,正则引擎无法识别这种错误写法,加上getcomuni.php的排除项后错误累积触发了500。
错误点分析
原规则里的\maintenance\.html、\misc\.php、\getcomuni\.php都是错误的:反斜杠只需要用来转义.(因为.在正则里代表任意字符),普通字母开头的文件名不需要加反斜杠。
修正后的维护重定向规则
把RewriteCond的正则改成正确写法即可,同时注意把重定向规则放在RewriteBase /之后(部分主机要求RewriteBase先声明,否则规则可能不生效):
RewriteEngine on RewriteBase / # 维护模式重定向:排除指定页面与静态资源 RewriteCond %{REQUEST_URI} !(maintenance\.html|\.gif|\.jpg|\.png|misc\.php|getcomuni\.php)$ [NC] RewriteRule ^ /maintenance.html [R=302,L]
完整修正后的.htaccess代码
RewriteEngine on RewriteBase / # 维护模式重定向:排除指定页面与静态资源 RewriteCond %{REQUEST_URI} !(maintenance\.html|\.gif|\.jpg|\.png|misc\.php|getcomuni\.php)$ [NC] RewriteRule ^ /maintenance.html [R=302,L] # Google SEO workaround for search.php highlights: # Make this rule the first rewrite rule in your .htaccess! RewriteRule ^([^&]*)&(.*)$ http://myforum.altervista.org/$1?$2 [L,QSA,R=301] # Google SEO 404: ErrorDocument 404 /misc.php?google_seo_error=404 # Google SEO Sitemap: RewriteRule ^sitemap\-([^./]+)\.xml$ misc.php?google_seo_sitemap=$1 [L,QSA,NC] # Google SEO URL Forums: RewriteRule ^Forum\-([^./]+)$ forumdisplay.php?google_seo_forum=$1 [L,QSA,NC] # Google SEO URL Threads: RewriteRule ^Thread\-([^./]+)$ showthread.php?google_seo_thread=$1 [L,QSA,NC] # Google SEO URL Announcements: RewriteRule ^Announcement\-([^./]+)$ announcements.php?google_seo_announcement=$1 [L,QSA,NC] # Google SEO URL Users: RewriteRule ^User\-([^./]+)$ member.php?action=profile&google_seo_user=$1 [L,QSA,NC] # Google SEO URL Calendars: RewriteRule ^Calendar\-([^./]+)$ calendar.php?google_seo_calendar=$1 [L,QSA,NC] # Google SEO URL Events: RewriteRule ^Event\-([^./]+)$ calendar.php?action=event&google_seo_event=$1 [L,QSA,NC]
另外注意:原代码里的&是HTML转义后的字符,在.htaccess里直接写&即可,不影响但更规范。
内容的提问来源于stack exchange,提问作者FDB
相关产品推荐
相关产品推荐

