繁体   English   中英

htaccess重命名文件夹路径

[英]htaccess rename folder path

我想从我的网站重写网址。 我知道我必须使用htaccess文件来执行此操作,但是我不明白如何解决该问题,或者给它提供了一种方法,可以在不更改文件夹结构的情况下更改php中的url路径? 我在此文件夹中有很多文件:

本地主机/网站/

例:

本地主机/网站/ test.php的

我想将网址重写为:

本地主机/ test.php的

但我不想移动文件。

RewriteEngine On 
RewriteRule ^(.*) sites/test.php [L]

编辑

我之前的答案无效。 现在可以了。

假设您的网络服务器是Apache服务器:

使用以下内容在文档根目录中创建一个.htaccess文件。 如果不起作用,请检查是否启用了mod_rewrite。

第一个RewriteRule重定向到新URL,并且RewriteCond确保此规则仅用于外部重定向。

第二个确保新URL确实有效

RewriteEngine On

# Check that the request URI is sites/test.php
RewriteCond %{REQUEST_URI} ^sites/test.php
# Redirect the browser to the new URL
RewriteRule ^sites/test.php /test.php [R,QSA,L]

# Rewrite the new URL to use the file in the old location    
RewriteRule ^test.php home/test.php [QSA,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM