dongxia4880 2017-01-05 15:22
浏览 62
已采纳

网址友好,不会丢失样式css / js / images

I have a website too extensive editing the URLs of styles css and files js, images would cost me too much time.

I'm working at localhost

localhost/project/index.php

The friendly url I want to have:

localhost/project/index/

From this url

localhost/project/online.php

to this

localhost/project/online/video/hd/free/

I have observed this website http://crazycafe.net/demos/seo/ and its source code, the styles css is maintained this way: <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"> without adding an absolute URL to styles css and their files and images.

How do i create a friendly url this way?

If the user modifies the url in this way:

http://crazycafe.net/demos/seo

Redirect to this way:

http://crazycafe.net/demos/seo/

On the other hand like conserving the styles css the files js and images, without having to modify to an absolute route.

My file directory is:

assets/css/style.css
assets/js/app.js
assets/fonts/icons/image.png
assets/fonts/ttf/roboto.ttf
assets/img/system/image.png
assets/img/logo.png

Note:

I found this question in SO, of how conserve CSS styles.

But I do not understand the use of friendly URL - .httaccess

  • 写回答

1条回答 默认 最新

  • dongzhanlu8890 2017-01-05 15:47
    关注

    You need to switch on mod_rewrite and use it. Example:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^folder1.*$ http://example.com/ [R=301,L]
    

    Folder-based example:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^folder1/(.*)$ http://gs.mt-example.com/folder2/$1 [R=301,L]
    

    Your case:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^online.php$ project/online/video/hd/free/$1 [R=301,L]
    

    See more here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用