1

我刚刚加载并激活了重写引擎,但不知道如何设计一个好的 .htaccess 文件。我想像这样转换链接:

http://localhost/index.php?u=username --> http://localhost/username/
http://localhost/index.php?id=1&v=2 --> http://locahost/1x2

谢谢你的帮助!

4

1 回答 1

1

URL重写改变:

ht*p://localhost/username/ -- 以 / 结尾是可选
的 > ht*p://localhost/index.php?u=username

ht*p://localhost/1x2 -- 不区分大小写(匹配 4X4)
到 > ht*p://localhost/index.php?id=1&v=2

.htaccess内容:

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteCond %{REQUEST_URI} !^/index.php [NC]
RewriteCond %{REQUEST_URI} ^/([^/\d]+)/?$ [NC]
RewriteRule (.*) index.php?u=%1 [L]

RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteCond %{REQUEST_URI} ^/(\d+)x(\d+)/?$ [NC]
RewriteRule (.*) index.php?id=%1&v=%2 [L]
于 2013-04-27T17:29:11.453 回答