简单的网站结构重写规则PHP的GET参数 [英] Simple website structure RewriteRule for PHP GET parameters

查看:122
本文介绍了简单的网站结构重写规则PHP的GET参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以重写下面的例子?

How can I rewrite the examples below?

www.domain-name.com/site-name/index.php?lang=en-us&page=home
  www.domain-name.com/site-name/index.php?lang=en-us&page=about
  www.domain-name.com/site-name/index.php?lang=pt-pt&page=inicio
  www.domain-name.com/site-name/index.php?lang=pt-pt&page=sobre

www.domain-name.com/site-name/index.php?lang=en-us&page=home
www.domain-name.com/site-name/index.php?lang=en-us&page=about
www.domain-name.com/site-name/index.php?lang=pt-pt&page=inicio
www.domain-name.com/site-name/index.php?lang=pt-pt&page=sobre

要这样:

www.domain-name.com/site-name/en-us/home.html
  www.domain-name.com/site-name/en-us/about.html
  www.domain-name.com/site-name/pt-pt/inicio.html
  www.domain-name.com/site-name/pt-pt/sobre.html

www.domain-name.com/site-name/en-us/home.html
www.domain-name.com/site-name/en-us/about.html
www.domain-name.com/site-name/pt-pt/inicio.html
www.domain-name.com/site-name/pt-pt/sobre.html

我设法获得的的参数。这是我有:

I managed to get the page parameter. This is what I have:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /site-name/

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*?)/?$ index.php?page=$1 [L]
</IfModule>

我不知道该怎么追加的.html到底为人人的的参数和正则表达式是真的不关我的事,所以有一些很难搞清楚林怎么了 - 一部分为的参数将起作用。我注意到,网站会很奇怪,当不正确的URL的类型。

I don't know how to append .html in the end for all "page" parameters and regex are really not my thing, so Im having some hard time figuring out how the "-" part for the "lang" parameter will work. I've noticed that website gets weird when incorrect url's are typed.

以后就会有它自己的域名,但我想更改的RewriteBase /网站名称/ 的RewriteBase / 将修复它,对吗?

Later it will have it's own domain name, but I guess changing from "RewriteBase /site-name/" to "RewriteBase /" will fix it, right?

我不很了解,但我认为一些标志缺失太(搜索引擎优化的目的)。

I don't know much about it, but I think some flags are missing too (for SEO purposes).

推荐答案

您可以使用:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /site-name/

    RewriteRule ^([^/]+)/(.+?)\.html?$ index.php?lang=$1&page=$2 [NC,L,QSA]
</IfModule>

这篇关于简单的网站结构重写规则PHP的GET参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆