我打电话给一个特定产品的新页面因此需要创建一个独特的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