。htaccess将example.com/path1/path2/index.php的URL重写为example.com/home

问题描述 投票:0回答:1

我有一个看起来像这样的URL:

http://example.com/path1/path2/index.php

我将如何将该URL转换为:

http://example.com/home

我该怎么做?

apache .htaccess
1个回答
0
投票

要在内部将/home重写为/path1/path2/index.php,请在.htaccess中使用mod_rewrite进行以下操作:

RewriteEngine On

RewriteRule ^home$ path1/path2/index.php [L]

将URL从example.com/path1/path2/index.php重写为example.com/home

注意,重写过程是朝另一个方向进行的。您正在将URL从/home重写为基础文件系统路径/path1/path2/index.php

然后您需要将您在应用程序中链接到的URL实际更改为/home,然后.htaccess完成重写此“ URL”的工作。

© www.soinside.com 2019 - 2024. All rights reserved.