将目录添加到所有url mod重写

时间:2016-10-25 18:58:51

标签: apache .htaccess mod-rewrite

我在localhost上使用htaccess,我的htaccess是:

RewriteEngine On
RewriteBase /website/files/

RewriteRule ^home/?$ home.php  [NC]
RewriteRule ^page/?$ page.php  [NC]

此网址有效:

http://localhost/website/files/home

但是当将鼠标悬停在页面上的链接上时,它们显示为:

http://localhost/page

而不是:

http://localhost/website/files/page

页面中的所有链接都设置为:

<a href="/page">page</a>

如何将目录添加到htaccess中的所有网址?

1 个答案:

答案 0 :(得分:0)

在站点根目录.htaccess:

中创建此.htaccess
RewriteEngine On

RewriteRule .* website/files/$0 [L]

如您所示,请保留website/files/.htaccess