htaccess 代码导致 500 错误

发布于 2024-11-07 20:00:17 字数 734 浏览 0 评论 0原文

我正在按照一本书教程(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

策马西风 2024-11-14 20:00:17

您的 .htaccess 中存在一些轻微的语法错误。我已经修复了它们,请尝试以下操作:

Options +FollowSymlinks -MultiViews
RewriteEngine on

# For sales:
RewriteRule ^shop/sales/?$ sales.php [L,NC]
# For the primary categories:
RewriteRule ^shop/([^/]*)/?$ shop.php?type=$1 [L,NC]
# For specific products:
RewriteRule ^browse/([^/]*)/([^/]*)/([0-9])/?$ browse.php?type=$1&category=$2&id=$3 [L,NC]
# For HTTPS pages:
RewriteCond %{HTTPS} off
RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L,NC]

There are some minor syntax errors in your .htaccess. I have fixed them, pls try this:

Options +FollowSymlinks -MultiViews
RewriteEngine on

# For sales:
RewriteRule ^shop/sales/?$ sales.php [L,NC]
# For the primary categories:
RewriteRule ^shop/([^/]*)/?$ shop.php?type=$1 [L,NC]
# For specific products:
RewriteRule ^browse/([^/]*)/([^/]*)/([0-9])/?$ browse.php?type=$1&category=$2&id=$3 [L,NC]
# For HTTPS pages:
RewriteCond %{HTTPS} off
RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L,NC]
无人接听 2024-11-14 20:00:17

您的 Apache 配置中是否启用了 Mod_Rewrite?某些提供商不会在共享主机上激活它。

Is Mod_Rewrite enabled in your Apache configuration? Some providers do not activate it on shared hosts.

書生途 2024-11-14 20:00:17

我认为问题是@sparky672在评论中建议的,即我正在复制和粘贴,也许隐形字符潜入

我现在可以使用了

<IfModule mod_rewrite.c>
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]
</IfModule>

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

<IfModule mod_rewrite.c>
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]
</IfModule>
维持三分热 2024-11-14 20:00:17

你在哪里复制&粘贴自?

如果您将其从网页上拉下来,那么您就引入了各种不可见的字符。如果您使用 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文