根据多种条件重写



我似乎无法弄清楚如何使我的.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

最简单的情况

URL重写的最简单情况是重命名单个静态网页,这要比上面的B& q示例要容易得多。要使用Apache的URL重写函数,您需要在网站的文档root中创建或编辑.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 example.com/about

使用此规则

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

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

这是一些有用的链接

  • 为初学者重写URL
  • apache模块mod_rewrite
  • URL重写指南

欢呼!

mudassar ali

将此代码放在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]

最新更新