mod_rewrite 重定向发送状态码 500
mod_rewrite redirect sends status code 500
我目前正在使用这个 .htaccess:
RewriteEngine on
RewriteRule ^profile/([^/.]+)/?$ p.php?un= [L]
它运行良好,它从
重定向
p.php?un=2 to profile/Eddy
但是当我将其添加到代码中以从 brand.php?b=3 重定向到 brand/name
RewriteRule ^brand/([^/.]+)/?$ brand.php?b= [L]
它总是发送 status/error 代码 500。
您的 .htaccess 有几个问题!
文件应以:
开头
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
下一部分的前两行是什么?
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.servicebox.com.ng [NC]
RewriteRule ^(.*)$ http://servicebox.com.ng/ [L,R=301]
你的上面的规则应该来了(可能仍然不起作用)
RewriteRule ^profile/([^/.]+)/?$ p.php?un= [L]
RewriteRule ^brand/([^/.]+)/?$ brand.php?b= [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
您可以试试这么小的 .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/ [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= [L,QSA,NC]
RewriteRule ^brand/([^/.]+)/?$ brand.php?b= [L,QSA,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/\.php -f [NC]
RewriteRule ^(.+?)/?$ .php [L]
我目前正在使用这个 .htaccess:
RewriteEngine on
RewriteRule ^profile/([^/.]+)/?$ p.php?un= [L]
它运行良好,它从
重定向p.php?un=2 to profile/Eddy
但是当我将其添加到代码中以从 brand.php?b=3 重定向到 brand/name
RewriteRule ^brand/([^/.]+)/?$ brand.php?b= [L]
它总是发送 status/error 代码 500。
您的 .htaccess 有几个问题! 文件应以:
开头Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
下一部分的前两行是什么?
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www.servicebox.com.ng [NC]
RewriteRule ^(.*)$ http://servicebox.com.ng/ [L,R=301]
你的上面的规则应该来了(可能仍然不起作用)
RewriteRule ^profile/([^/.]+)/?$ p.php?un= [L]
RewriteRule ^brand/([^/.]+)/?$ brand.php?b= [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
您可以试试这么小的 .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/ [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= [L,QSA,NC]
RewriteRule ^brand/([^/.]+)/?$ brand.php?b= [L,QSA,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/\.php -f [NC]
RewriteRule ^(.+?)/?$ .php [L]