我正在使用特定产品信息调用新页面,因此需要创建一个独特的 slug ,并需要调用它并查找有关该slug的相关信息。
目前我只是调用新页面,如:
www.site.com/page.php?var =" slugname"
但是想要成就:
www.site.com/slugname
任何人都有建议???
答案 0 :(得分:-2)
它被称为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个变量
# 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 它还会阻止用户访问需要隐藏的访问文件夹,如/ cache或/ images