2017-01-05 25 views
0

我有一個網站編輯樣式爲css和文件jsimages的網址太多,會花費我太多的時間。網址友好而不失風格css/js/images

我在本地主機工作

localhost/project/index.php 

友好的URL我想有:

localhost/project/index/ 

從這個網址

localhost/project/online.php 

這個

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

我觀察這個網站http://crazycafe.net/demos/seo/及其源代碼,css保持這樣的風格:<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"> 無需添加絕對URL將樣式css其文件和images

如何創建友好的URL這種方式?

如果用戶修改這樣的網址:

http://crazycafe.net/demos/seo 

重定向到這樣的:

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

在另一方面喜歡節約的樣式css文件jsimages,而不必修改爲絕對路線。

我的文件目錄是:

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 

注:

我發現這個question在SO,如何節約CSS樣式。

但我不明白,使用友好的URL的 - .httaccess

回答

0

你需要打開mod_rewrite的並使用它。例如:基於文件夾

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

例如:

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

您的情況:

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

查看更多here

+0

不工作,此錯誤顯示:服務器錯誤 –

+0

代碼可能與您的其他代碼在.htaccess中不兼容。嘗試做一些實驗並讓我知道結果。 –

+0

嗨! @LajosArpad結果是那些說服務器錯誤不顯示頁面並顯示錯誤。 –