【问题标题】:Add hyphen to clean url with htaccess使用 htaccess 添加连字符以清除 url
【发布时间】:2016-06-03 11:50:37
【问题描述】:

我的网站采用单页方法,所有 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=$1&identifier=$2&action=$3 [L]
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ ?ressource=$1&identifier=$2 [L]

#EOF

我已经添加了前三行来强制用户的客户端访问我的 https 站点。

现在我还想在标识符值中添加一个连字符,例如 article/terms-of-service

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

【问题讨论】:

  • NC 是忽略大小写,QSA 保留之前的查询字符串
  • @hjpotter92 好的,我尝试的另一个规则是RewriteRule ^([^/]*)$ ?ressource=$1 [L],它只会导致 500 内部服务器错误

标签: apache query-string clean-urls hyphen


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-13
    • 2012-11-28
    • 2020-05-25
    • 2019-09-16
    相关资源
    最近更新 更多