htaccess 规则给出 500 内部服务器错误

htaccess rule giving 500 internal server error

我在尝试重写 URL 时遇到错误。

来自这里:

www.example.com/products/product-details.php?alias=abc-def-123

为此:

www.example.com/products/abc-def-123

这是我的 .htaccess 文件

#Turn Rewrite Engine On
Options +FollowSymLinks -MultiViews
Options -Indexes

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ .html [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php [NC,L]

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^products/([a-zA-Z0-9-]+)$ products/product-details.php?alias= [NC,L]

</IfModule>

我正在打这个URL:

www.example.com/products/abc-def-123

更新:

使用您展示的示例,请尝试遵循以下规则。请确保将您的 htaccess 与您的产品文件夹一起保存在您的根文件夹中(而不是在其中)。

<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)/?$ https://example.com/ [L,NE,R=301]

RewriteCond %{THE_REQUEST} \s/products/.*\?alias=(\S+)\s
RewriteRule ^ /products/%1? [R=301,L]

RewriteRule ^products/(.*)/?$ products/product-details.php?alias= [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f [NC]
RewriteRule ^(.*)/?$ .html [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f [NC]
RewriteRule ^(.*)/?$ .php [NC,L]

</IfModule>

是啊!!!!!!! 我自己解决了我的问题,还要感谢@RavinderSingh13 的努力。

这是整个 .htaccess 文件

<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)/?$ https://example.com/ [L,NE,R=301]

RewriteRule ^products/([^/\.]+)?$ products/product-details.php?alias= [NC,L]  

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f [NC]
RewriteRule ^(.*)/?$ .html [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f [NC]
RewriteRule ^(.*)/?$ .php [NC,L]

</IfModule>