我打電話給一個特定產品的新頁面因此需要創建一個獨特的slu 012並需要調用它並查找有關該slug的相關信息。如何動態創建slu and並在codeingniter中生成新的URL
目前我打電話是新的一頁是這樣的:
www.site.com/page.php?var="slugname」
,但要使它像:
www.site.com/slugname
任何人都可以有建議?
我打電話給一個特定產品的新頁面因此需要創建一個獨特的slu 012並需要調用它並查找有關該slug的相關信息。如何動態創建slu and並在codeingniter中生成新的URL
目前我打電話是新的一頁是這樣的:
www.site.com/page.php?var="slugname」
,但要使它像:
www.site.com/slugname
任何人都可以有建議?
它被稱爲SEO Url。這是一個很好的tuturial http://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
在你的項目的根目錄下創建一個.htaccess。 添加以下代碼
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d //SCRIPT is mostly your index.php
//actually it will be something like this
RewriteCond %{index.php} !-f
RewriteRule ^var/(\d+)*$ index.php?var=$1 //in this case its your index and your link is var.
//Now the browser will rewrite your url in yoursitename.com/myvar or whatever you want instead of yoursitename.com/?myvar=somevar
不要忘記刪除//註釋
編輯:使用2個瓦爾在您的網址只是創建另一個變種在你的.htaccess
我用這是我的網站。其優良的工作多達4個瓦爾在url
# Bestaande bestanden of mappen uitsluiten
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule ^(.*?)$ $1 [L]
RewriteCond %{REQUEST_URI} !^/cache
RewriteCond %{REQUEST_URI} !^/images
RewriteCond %{REQUEST_URI} !.*\.(css|jpg|gif|zip|js)
RewriteRule ^(.*)/(.*)/?$ index.php?client=$1&slug=$2 [L]
RewriteRule ^(.*) index.php?client=$1 [L]
#RewriteRule ^(.*)/?$ http://www.google.com/ [R]
這 yourwebsite.com/client.php?slug=demo 將輸出 yourwebsite.com/client/demo 它也阻止訪問文件夾的用戶是需要隱藏像/緩存或/圖片
我現在的網址是這樣的: ** www.site.com/client/detail?slug=demo** ,但要使它像: ** www.site.com /客戶/演示* * –
也不正確。在編輯中如何填入'$ 1 .. $ 3'? – arco444
$ 1 .. $ 3是你的var在url中給出的值。像index.php?demo = value將是site.com/value –
可能重複的[如何創建動態URL?](http://stackoverflow.com/questions/6963144/how-do-i-create-dynamic-urls) –
[如何設置動態路由以在CodeIgniter中使用slug?](http://stackoverflow.com/questions/15367197/how-to-set-dynamic-route-to-use-slug-in-codeigniter) – CBroe