htaccess 代码导致 500 错误
我正在按照一本书教程(Larry Ullman 的《Effortless Ecommerce》)来构建一个电子商务网站。当我将以下代码添加到 htaccess 文件以重写 URL 并强制执行 SSL 时,当我尝试加载网站时,它会返回 500 错误。
有谁知道问题/解决方案可能是什么?
RewriteEngine on
# For sales:
RewriteRule ^shop/sales/?$ sales.php
# For the primary categories:
RewriteRule ^shop/([A-Za-z\ ] )/?$ shop.php?type=$1
# For specific products:
RewriteRule ^browse/([A-Za-z\ \-] )/([A-Za-z\ \-] )/([0-9] )$ browse.php?type=$1&category=$2&id=$3
# For HTTPS pages:
RewriteCond %{HTTPS} off
RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]
I'm following a book tutorial (Effortless Ecommerce by Larry Ullman) to build an ecommerce site. When I add the following code to my htaccess file to rewrite URLs and also enforce SSL, it returns a 500 error when I try to load my site.
Does anyone have any ideas what the problem/solution might be?
RewriteEngine on
# For sales:
RewriteRule ^shop/sales/?$ sales.php
# For the primary categories:
RewriteRule ^shop/([A-Za-z\ ] )/?$ shop.php?type=$1
# For specific products:
RewriteRule ^browse/([A-Za-z\ \-] )/([A-Za-z\ \-] )/([0-9] )$ browse.php?type=$1&category=$2&id=$3
# For HTTPS pages:
RewriteCond %{HTTPS} off
RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的 .htaccess 中存在一些轻微的语法错误。我已经修复了它们,请尝试以下操作:
There are some minor syntax errors in your .htaccess. I have fixed them, pls try this:
您的 Apache 配置中是否启用了 Mod_Rewrite?某些提供商不会在共享主机上激活它。
Is Mod_Rewrite enabled in your Apache configuration? Some providers do not activate it on shared hosts.
我认为问题是@sparky672在评论中建议的,即我正在复制和粘贴,也许隐形字符潜入
我现在可以使用了
I think the problem was what @sparky672 suggested in the comments, namely that I was copying and pasting and maybe invisible characters snuck in
I got this to work now
你在哪里复制&粘贴自?
如果您将其从网页上拉下来,那么您就引入了各种不可见的字符。如果您使用 MS Word,您还会引入无关的不可见内容。
尝试使用好的文本编辑器,检查不可见的垃圾并从那里复制/粘贴。或者直接将其全部手动输入到控制面板编辑器中。
就我个人而言,我使用一个好的文本编辑器并通过 FTP 上传(确保它处于 ASCII 文本模式)。
Where are you copying & pasting it from?
If you're pulling it off a web page, then you're introducing all kinds of invisible characters. If you're using MS Word, you're also introducing extraneous invisibles.
Try using a good text editor, check for invisible junk and copy/paste from there. Or just type it all out long-hand into your control panel editor.
Personally, I use a good text editor and upload via FTP (making sure it's in ASCII text mode).