[英]Simple pretty urls with .htaccess
I have a one page blog php website.我有一个单页博客 php 网站。 Content is dynamicaly loaded based on get parameters.
内容是根据获取参数动态加载的。 I would like to use my htaccess to make pretty urls.
我想用我的 htaccess 制作漂亮的网址。 I have these urls:
我有这些网址:
website.com/index.php?category=review&page=1
And I would like to have this:我想要这个:
website.com/category/review/page/1
And I also use article as get parameter.而且我还使用文章作为获取参数。 So I would like to change this:
所以我想改变这个:
website.com/index.php?article=12345-name-of-article
To this:对此:
website.com/article/12345-name-of-article
I am totally new to htaccess, so any help would be appreciated.我对 htaccess 完全陌生,因此将不胜感激。
I tried this rewrite rule: RewriteRule ^article/([0-9a-zA-Z_-]+)$ index.php?article=$i [NC,L]
.我尝试了这个重写规则:
RewriteRule ^article/([0-9a-zA-Z_-]+)$ index.php?article=$i [NC,L]
。 It worked somehow, but php script does not recognize url parameters.它以某种方式工作,但 php 脚本无法识别 url 参数。 So it does not work.
所以它不起作用。
Thank you very much!非常感谢!
You need to use QSA - When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one.您需要使用 QSA - 当替换 URI 包含查询字符串时,RewriteRule 的默认行为是丢弃现有的查询字符串,并将其替换为新生成的查询字符串。 Using the [QSA] flag causes the query strings to be combined.
使用 [QSA] 标志会合并查询字符串。 :
:
RewriteEngine On
RewriteRule ^article/([\w-]+)(?:\.html|/)?$ index.php?article=$1 [NC,QSA,L]
RewriteRule ^category/([\w-]+)/page/([\w-]+)(?:\.html|/)?$ index.php?category=$1&page=$2 [NC,QSA,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.