开发者

apache mod_rewrite, simple question

I have domain and I am wanting to forward virtual folder to identify company e.g

www.domain.com/开发者_开发知识库CompanyA
www.domain.com/CompanyB

CompanyA and CompanyB folders don't exist, and I want that to become the querystring e.g

www.domain.com/?CompanyA etc..

How do I do this with mod_rewrite?

Many thanks,


Add the following RewriteRule:

RewriteRule ^/([A-Za-z]+)$ /?$1

This will capture any sequence of one or more lower and uppercase letters into the first match group (that can be accessed by $1). You may then use $1 in the second parameter of the rewrite rule to mean the string matched. For example, you could use:

RewriteRule ^/([A-Za-z]+)$ /render.php?page=$1

if you want to use a file other than your index.php (or equivalent) to handle the conditional rendering logic.


RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ /index.php?query=$1 [L,QSA]

QSA let you keep incoming query string intact.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜