为什么我的.htaccess与mod_rewrite给我一个500错误?

时间:2016-03-20 09:14:17

标签: .htaccess mod-rewrite

我的.htaccess看起来像这样:

<FilesMatch ".(eot|ttf|otf|woff|svg)">
 Header set Access-Control-Allow-Origin "*"
 </FilesMatch>

ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [R=302,L,NE]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302,NE]

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]

RewriteCond %{THE_REQUEST} \ /(.+)\.php
RewriteRule ^ /%1 [L,R=302,NE]

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(.*?)\.(www\.)?domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com/page?user=%1 [L,QSA,R=302,NE]

***THIS IS WHERE I INSERT THE NEW RULE***

RewriteRule ^([^/]*)-([0-9]+)\.html$ product?name=$1&product_id=$2 [L,QSA]

到目前为止一切顺利。一切正常。例如,当有人前往scoobydoo.domain.com时,他们会被重定向到domain.com/page?user=scoobydoo。现在我还想掩盖页面,这样当有人去www.domain.com/scoobydoo时,他们真的显示domain.com/page?user=scoobydoo,所以我添加了这个:

RewriteRule ^([^/]*)$ /page?user=$1 [L]

然而,当我将其添加到第二行时,它不起作用。

这里有什么问题?

1 个答案:

答案 0 :(得分:2)

您的规则没问题,但您需要从中排除您的真实文件和目录:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /page?user=$1 [L,QSA]