【问题标题】:RewriteRule works for one condition but fails for otherRewriteRule 适用于一种情况,但适用于其他情况
【发布时间】:2026-01-08 01:20:03
【问题描述】:
  Options +FollowSymLinks -MultiViews
  # Turn mod_rewrite on
  RewriteEngine On 
  RewriteRule apartments  projects.html    [NC,L]  
  RewriteRule ^/apartments/cat/name2/?$    project-details.html    [NC,L]

上面的重写规则是为了改变 url 而创建的 1) www.domain.com/apartmentswww.domain.com/projects.html1) www.domain.com/apartments/cat/name2/project-details.html

但是规则 1 成功规则 2 失败!两个 html 都存在

【问题讨论】:

    标签: html apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    试试这个:

    RewriteRule ^apartments/?$  projects.html    [NC,L]
    RewriteRule ^apartments/cat/name2/?$    project-details.html    [NC,L]
    

    【讨论】:

    • 现在像<link rel="stylesheet" href="css/bootstrap.min.css">这样的外部脚本和css 不工作。他们被重定向到apartments/cat/name2/css/bootstrap.min.css
    • 在你的链接href中给出来自http://yoursite.com/style/css/bootstrap.min.css的完整路径,然后它就像魅力一样工作。
    • 随时为您提供帮助 :)
    最近更新 更多