mod_rewrite重定向发送状态代码500

时间:2015-01-28 05:42:05

标签: php .htaccess

我目前正在使用 .htaccess

RewriteEngine on
RewriteRule ^profile/([^/.]+)/?$ p.php?un=$1 [L]

它运行良好,从

重定向
p.php?un=2 to profile/Eddy

但是,当我将此代码添加到代码中以从 brand.php?b = 3 重定向到品牌/名称

RewriteRule ^brand/([^/.]+)/?$ brand.php?b=$1 [L]

它始终发送状态/错误代码500。

2 个答案:

答案 0 :(得分:2)

你可以试试这个更小的.htaccess:

# multiple file types
<FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
 Order Allow,Deny
 Deny from all
</FilesMatch>                   

AddHandler application/x-httpd-php54  .php54 .php

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/php
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteBase /

# proc/self/environ? no way!
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^ index.php [F,L]

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NE]

RewriteRule ^profile/([^/.]+)/?$ p.php?un=$1 [L,QSA,NC]
RewriteRule ^brand/([^/.]+)/?$ brand.php?b=$1 [L,QSA,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

答案 1 :(得分:1)

你有几个问题.htaccess! 文件应该从:

开始
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /

下一部分的前两行是什么?

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.servicebox.com.ng [NC]
RewriteRule ^(.*)$ http://servicebox.com.ng/$1 [L,R=301]

这应该是你的规则从上面(可能仍然无效)

RewriteRule ^profile/([^/.]+)/?$ p.php?un=$1 [L]
RewriteRule ^brand/([^/.]+)/?$ brand.php?b=$1 [L]

最后的所有其他内容:

# hide .php extension
#To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

#To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

ErrorDocument 400 http://www.servicebox.com.ng/400
#All other ErrorDocuments... and following non related stuff