请一点帮助重写网址!

时间:2011-06-03 21:35:27

标签: url mod-rewrite url-rewriting

我有一个关于网址重写的简短问题......

我有一个网站。我们说http://www.example.com/

有一些子网站:

http://www.example.com/a.php
http://www.example.com/b.php

等...

和一些“特殊”网址如

http://www.example.com/c.php?i=1#link1
http://www.example.com/c.php?i=1#link2
http://www.example.com/c.php?i=2#link1

现在我想编写一个.htaccess文件,将当前网址转换为重写的网址,如

http://www.example.com/a/
http://www.example.com/c/1/#link1

我不是网址重写的专家,所以有人可以帮帮我吗?

最好的反馈。

2 个答案:

答案 0 :(得分:1)

RewriteRule ^a$ a.php [L]

RewriteRule ^c/(.*)/(.*) c.php?i=$1$2

答案 1 :(得分:1)

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^a.php a/
RewriteRule ^b.php b/

就静态页面而言,你应该工作,你不能重写哈希,因为哈希不会发送到服务器(如here所述)。如果您需要重写哈希,我建议将哈希值更改为另一个GET变量(例如u),在这种情况下,只需将其添加到您的htaccess:RewriteRule ^c.php?i=(.*)&u=(.*) c/$1/$2。如果你只是打算离开锚点,你可以从重写中省略它,一切都应该没问题(...因为服务器永远不会看到哈希/井符号),在这种情况下你应该把它添加到你的代码中{ {1}}。