Php mod_重写重定向发送状态代码500

Php mod_重写重定向发送状态代码500,php,.htaccess,Php,.htaccess,我当前正在使用此.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, h

我当前正在使用此.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]
它工作得很好,它可以从

p.php?un=2 to profile/Eddy
但是当我把它添加到代码中,从brand.php?b=3重定向到brand/name时


它总是发送状态/错误代码500。

您有几个问题。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]
这里应该是你上面的规则(可能仍然不起作用)

最后还有其他的东西:

# 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

您可以尝试更小的尺寸。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]
#多种文件类型
命令允许,拒绝
全盘否定
AddHandler应用程序/x-httpd-php54.php54.php
#压缩文本、html、javascript、css、xml:
AddOutputFilterByType泄气文本/普通
AddOutputFilterByType DEFLATE text/php
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE应用程序/xml
AddOutputFilterByType DEFLATE应用程序/xhtml+xml
AddOutputFilterByType DEFLATE应用程序/rss+xml
AddOutputFilterByType DEFLATE应用程序/javascript
AddOutputFilterByType DEFLATE应用程序/x-javascript
选项+后续符号链接-多视图-索引
重新启动发动机
重写基/
#过程/自我/环境?不可能!
重写cond%{QUERY_STRING}proc/self/environ[或]
#阻止任何试图通过URL设置mosConfig值的脚本
重写cond%{QUERY\u STRING}mosConfig\[a-zA-Z\]{1,21}(\\%3D)[或]
#阻止任何试图通过URL发送base64_编码垃圾的脚本
RewriteCond%{QUERY_STRING}base64_encode.*(.*)[或]
#阻止在URL中包含标记的任何脚本
重写cond%{QUERY_STRING}(|%3E)[NC,或]
#阻止任何试图通过URL设置PHP全局变量的脚本
重写条件%{QUERY\u STRING}全局(|[|\%[0-9A-Z]{0,2})[或]
#阻止任何试图通过URL修改_请求变量的脚本
重写条件%{QUERY\u STRING}{u请求(|[|\%[0-9A-Z]{0,2})
#将所有被阻止的请求发送到主页,出现403禁止错误!
重写规则^index.php[F,L]
重写cond%{HTTP_HOST}^www\.(.+)$[NC]
重写规则^(.*)$http://%1/$1[R=301,L]
##php扩展名
#从外部将/dir/foo.php重定向到/dir/foo
重写cond%{THE_REQUEST}^[A-Z]{3,}\s([^.]+)\.php[NC]
重写规则^1[R,L,NE]
重写规则^profile/([^/]+)/?$p.php?un=$1[L,QSA,NC]
重写规则^brand/([^/]+)/?$brand.php?b=$1[L,QSA,NC]
##在内部将/dir/foo重定向到/dir/foo.php
重写cond%{REQUEST_FILENAME}!-d
RewriteCond%{DOCUMENT_ROOT}/$1\.php-f[NC]
重写规则^(+?)/?$$1.php[L]

您是否在没有使用
[L]
标志的情况下进行了尝试?在没有重写条件的情况下,可能会出现问题,并且似乎对您没有必要。在我的本地计算机上尝试时,我没有收到500个错误(只有404个错误,因为该站点不存在)|?用于什么?这是整个图案填充文件。可能错误不在
mod_rewrite
中,而是在
brand.php
中。试试看
brand.php?b=一些合适的品牌名
,行吗?仍然不走运。我们会看到,他应该首先清理htaccess,还有一个seccong mod_rewrite和al因此,改变文件中规则博客的顺序是的,看起来更好:)@anubhava你能更详细地向我解释一下(我今天早上一定吃了太多的弯腰药:-)OP的重写规则是如何工作的(或不工作的)?在我看来,“profile/Eddy”将被重写为“p.php?un=Eddy”。OP示例中的“2”从何而来?为什么OP的示例似乎落后于实际完成的重写?抱歉,但我“不明白”原始问题或您的解决方案的原因(其中似乎包含与OP不起作用的完全相同的重写规则)解决了问题。请教我钓鱼!实际上OP提供了。htaccess是这样的:如果你将其与我的答案进行比较,那么它将更有意义。
# 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
# 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]