我有一个看起来像这样的URL:
http://example.com/path1/path2/index.php
我将如何将该URL转换为:
http://example.com/home
我该怎么做?
要在内部将/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”的工作。