Php .htaccess-重写一个uri,但全部重定向到HTTPS

Php .htaccess-重写一个uri,但全部重定向到HTTPS,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我真的很难得到正确的访问权限。我基本上想要转换 例如,product.php?sku=M1234以显示为M1234.php,并能够键入../M1234.php以执行该操作。我还希望网站上的所有网页都是HTTPS 我试过这个: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,N] RewriteRule ^([^/]*)\.html$ /p

我真的很难得到正确的访问权限。我基本上想要转换

例如,product.php?sku=M1234以显示为M1234.php,并能够键入../M1234.php以执行该操作。我还希望网站上的所有网页都是HTTPS

我试过这个:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,N]

RewriteRule ^([^/]*)\.html$ /products/product.php?product_id=$1 [L]
没有成功。任何建议都将不胜感激

非常感谢使用:

RewriteRule    ^([A-Za-z0-9-]+)/?$    /products/product.php?sku=$1    [NC,L]    # Handle product requests

这将使用
website.com/test
请求
website.com/products/product.php?sku=test

1。删除
N
-标志,因为它是可循环的。2.正则表达式
^([^/]*)\.html$
确实匹配
/M1234.html
,但此
([^/]*)\.html$
也对应于
/any/M1234.html