flat url rewriting:在HTML锚点中删除路径

时间:2016-10-14 07:47:28

标签: html .htaccess url-rewriting

在C:\ xampp \ htdocs \ myname \ myproject \ index.html我有

<a href="/aboutus">About Us</a>

这应链接到C:\ xampp \ htdocs \ myname \ myproject \ aboutus.html。

在我的localhost中,我希望网址看起来像这样:

localhost/myname/myproject/
localhost/myname/myproject/aboutus

但是,我似乎无法弄清楚如何编写网址重写规则以使其工作。 唯一有效的是如果我把路径放在html中:

<a href="/myname/myproject/aboutus">About Us</a>

但我不想这样做。

我的C:\ xampp \ htdocs \ myname \ myproject \ .htaccess文件:

<IfModule mod_rewrite.c>
# Enable url rewriting
RewriteEngine On 

RewriteBase /myname/myproject/

# Don't rewrite explictly requested paths
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d   

# URL rewriting rules
#TEST RewriteRule aboutus /myname/myproject/aboutus.html
RewriteRule ^([0-9]+).html/$ $1\.html

</IfModule>

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

尝试更改:

RewriteRule ^([0-9]+).html/$ $1\.html

RewriteRule ^([0-9A-Za-z\-_]+)/?$ $1\.html

你做错了是正则表达式。您只允许页面名称中的字符0-9。另请注意最后的/?。这是为了制作/ optional。

相关问题