dpwqicw157673 2017-03-28 17:54
浏览 112
已采纳

使用.htaccess更改url中的目录show

I am trying to change the url that show in the addressbar. Code in .htaccess:

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^Home?$  index.php [NC,L]
RewriteRule    ^about-us?$  aboutus.php [NC,L] 
RewriteRule    ^contact?$  contact.php [NC,L]
RewriteRule    ^products?$  products.php [NC,L]

RewriteRule    ^products/led-bulb?$  led-bulb.php [NC,L]

Explain: All page in the same directory and 4 first rewrite rule is ok, but the last rewrite rule has problem.(products/led-bulb directory not exist). Problem: last rule when loaded the [led-bulb.php] it not loaded any style and show the page without any style and design.

  • 写回答

1条回答 默认 最新

  • dongou6632 2017-03-28 18:01
    关注

    Your last rule is also working fine but you are facing style/image display problem due to your use of relative paths.

    You can add this just below <head> section of your page's HTML:

    <base href="/" />
    

    so that every relative URL is resolved from that base URL and not from the current page's URL.

    Also your rules should be making trailing slash optional like this:

    RewriteEngine On
    
    RewriteRule ^Home/?$ index.php [NC,L]
    RewriteRule ^about-us/?$ aboutus.php [NC,L] 
    RewriteRule ^contact/?$ contact.php [NC,L]
    RewriteRule ^products/?$ products.php [NC,L]
    
    RewriteRule ^products/led-bulb/?$  led-bulb.php [NC,L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料