.htaccess 基于多个条件重写规则

li9yvcax  于 2022-11-25  发布在  其他
关注(0)|答案(2)|浏览(138)

我似乎不知道如何让这些条件发生在我的.htaccess上

http://example.com/index.php?page=about
to
http://example.com/about

又同时

http://example.com/index.php?process=login
to
http://example.com/p/login

我自己也试过这样做,但我不知道如何同时做到这两点。
使用Apache

ttisahbt

ttisahbt1#

最简单的案例

URL重写最简单的例子是重命名一个静态网页,这比B&Q的例子要简单得多。要使用Apache的URL重写功能,你需要在你网站的文档根目录下(或者,不太常见的,在一个子目录下)创建或编辑.htaccess文件。

RewriteEngine On  
RewriteRule   about   index.php?page=about
RewriteRule   login   index.php?process=login

使用正则表达式

在URL重写中,只需匹配URL的路径,不包括域名或第一个斜杠

RewriteEngine On  
RewriteRule   ^about/?$   index.php?page=about  [NC]
RewriteRule   ^login/?$   index.php?process=login  [NC]

您也可以按照
example.com/index.php?page=about

example.com/about.html * 或**关于
使用此规则

RewriteEngine On 
RewriteRule ^([^/]*)\.html$ /index.php?page=$1 [L]

RewriteEngine On RewriteRule ^([^/]*)$ /index.php?page=$1 [L]

以下是一些有用的链接

干杯!干杯!
穆达萨尔·阿里

00jrzges

00jrzges2#

将以下代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

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

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

相关问题