[英]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.