添加连字符以使用 htaccess 清除 url

Add hyphen to clean url with htaccess

我的网站采用单页方法,所有 GET 请求的构建方式如下:index.php?ressource=product&identifier=5

为了获得干净的 url,我找到了一个创建这个的生成器:

RewriteEngine On
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule . https://%{HTTP_HOST}/ [L] HTTPS_HOST ???

RewriteEngine On
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ ?ressource=&identifier=&action= [L]
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ ?ressource=&identifier= [L]

#EOF

我添加了前三行以强制用户的客户端转到我的 https 站点。

现在我还想在标识符值中使用连字符,例如 article/terms-of-service

我做了一些研究,我需要使用 NC、QSA 或这两个标志,但每当我添加其中一个标志时,我都会收到服务器错误 500。

好的,我找到了在干净的 url 中添加连字符的解决方案:

RewriteEngine On
RewriteRule ^([a-z]+)/([0-9a-üA-Ü\-]+)/([a-z]+)$ ?ressource=&identifier=&kwargs= [L]
RewriteRule ^([a-z]+)/([0-9a-üA-Ü\-\%\s]+)$ ?ressource=&identifier= [L]
RewriteRule ^([a-z]+)$ ?ressource= [L]

必须将连字符添加到正则表达式中