htaccess 多参数重写规则

htaccess multiple parameters rewrite rule(htaccess 多参数重写规则)
本文介绍了htaccess 多参数重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我知道这个问题已经问过了,但找不到适合我的问题的任何内容.

I know this problem is over asked, but couldnt find anything fitting with my problem.

我目前正在创建一个网站,我的网址如下:

I'm currently creating a website, and my url are like :

www.foo.com/或 www.foo.com/index.php.它们可以采用 1、2 或三个不同的参数,例如

www.foo.com/ or www.foo.com/index.php. They can take 1, 2 ,or three different parameters like

www.foo.com/index.php?page=Home&lang=en&article=1

www.foo.com/index.php?page=Home&lang=en&article=1

我想要的是像

   www.foo.com/Home/

or www.foo.com/en/Home

or www.foo.com/Article/1

or www.foo.com/en/Article/1

page参数是必填的,其他两个都不是..我不能为我工作...任何帮助将不胜感激

The page parameter is required, other two are not.. I cant have anything working for me... Any help would be greately appreciated

非常感谢!

推荐答案

最好有单独的清洁规则.将此代码放入您的 DOCUMENT_ROOT/.htaccess 文件中:

Better to have separate clean rules. Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteRule ^index.php$ - [L]

RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]

RewriteRule ^([a-z]{2})/([^/]+)/?$ /index.php?page=$2&lang=$1 [L,QSA]

RewriteRule ^([a-z]{2})/([^/]+)/([0-9]+)/?$ /index.php?page=$2&lang=$1&article=$3 [L,QSA]

RewriteRule ^([^/]+)/([0-9]+)/?$ /index.php?page=$1&article=$2 [L,QSA]

这篇关于htaccess 多参数重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)