【问题标题】:Url rewrite 404 errorsUrl 重写 40​​4 错误
【发布时间】:2016-08-09 03:06:04
【问题描述】:

我正在尝试制作漂亮的 url,我的 htaccess 代码可以工作,但是每当 url 中有额外的 / 或缺少部分时,它会抛出 404 错误,而参数是可选的

localhost/1/en/home/ -> works
localhost/1/en/home/random -> 404 error
localhost/1/en -> 404 error

RewriteEngine on
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ index.php?id=$1&language=$2&page=$3 [L]

如何告诉 mod_rewrite 参数是可选的

【问题讨论】:

    标签: .htaccess mod-rewrite apache2


    【解决方案1】:

    您可以尝试使用此规则:

    RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)(/.*)?$ index.php?id=$1&language=$2&page=$3 [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-29
      • 2016-11-30
      • 2010-12-16
      • 2017-10-19
      相关资源
      最近更新 更多