如何在Apache中将查询参数重写为路径参数? [英] How can I rewrite query parameters to path parameters in Apache?

查看:67
本文介绍了如何在Apache中将查询参数重写为路径参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个网站正在尝试根据SEO进行优化.

I currently have a website that I am trying to optimize in terms of SEO.

我让该网站使用以下URL:

I've got the site working with URLs such as:

domain.com/?app=about

domain.com/?app=about

在我的应用中, $ _ GET [app] 设置为"about",符合预期.

In my app, $_GET[app] is set to 'about', as expected.

现在,我要这样做,以便像 domain.com/about 这样的URL被视为 domain.com/?app=about .

Now, I want to make it so that a URL like domain.com/about is treated as if it were domain.com/?app=about.

如何在Apache .htaccess文件中执行此操作?

How can I do this in an Apache .htaccess file?

推荐答案

这些被称为 RewriteRule s,它们非常简单:

These are known as RewriteRules, and they are fairly straightforward:

RewriteEngine on
RewriteRule ^about$ /index.php?app=about

此处是文档

就使其更通用而言,如何处理:

As far as making it more generic, how about this:

RewriteEngine on
RewriteRule ^([A-Za-z]+)$ /index.php?app=$1

这会将对/staff或/contact之类的任何请求重定向到index.php?app = [staff | contact]

This will make any request to something like /staff or /contact redirect to index.php?app=[staff|contact]

这篇关于如何在Apache中将查询参数重写为路径参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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