【问题标题】:php htaccess rewrite helpME please [closed]php htaccess 重写 helpME 请[关闭]
【发布时间】:2013-12-14 21:53:04
【问题描述】:
那里。
我是 htaccess 的新手。
请帮我 2 写 url 重写这些链接
网址:
- 网址 - index.php?page=news
- url - index.php?page=users&nickname=name
- 网址 - index.php?cat=Category
- url - index.php?cat=Category&seo-link=Title
- 网址 - index.php?cat=Category&sub_cat=SubCategory
- 网址 - index.php?cat=Category&sub_cat=SubCategory&seo-link=Title
- 网址 - index.php?page=gallery&album=albumName
- 网址 - index.php?page=gallery&album=albumName&image=imageName
需要是 URL 的:
- page.com/news/
- page.com/user/nickname/
- page.com/it-news/
- page.com/it-news/old/title/
- page.com/it-news/title/
类似的东西。
非常感谢。 :)
【问题讨论】:
标签:
php
.htaccess
variables
get
rewrite
【解决方案1】:
在您的主目录中创建一个文件并将此代码放入其中。调用文件.htaccess
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([A-Za-z0-9_-]+)/?([A-Za-z0-9_-]+)?/?$ index.php?cat=$1&page=$2 [NC,L]
带有数字和字母的括号是允许的,括号中的内容将转到 cat= 其中$1 在您的网址中是可变的。第二个括号将转到$2 所在的位置。例如,如果你在浏览器中输入/it-news,它实际上会加载index.php?cat=it-news&page=,如果你输入/it-news/datahere,它实际上会加载index.php?cta=it-news&page=datahere。每一个 ?在代码中意味着它之前的东西不需要存在,或者存在一次或不存在。 () 是回调顺序为 $1 $2 $3
希望这会有所帮助!
【解决方案2】:
一个例子
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^news/?$ index.php?cat=news [NC,L]
请注意!你最有 modRewrite 在 Apache 上活跃
你可以进一步阅读here