dongxia4880
dongxia4880
2017-01-05 15:22

网址友好,不会丢失样式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 dongzhanlu8890 4年前

    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.

    点赞 评论 复制链接分享

相关推荐