簡體   English   中英

將文件 url 重定向到 .htaccess 中的另一個頁面

[英]Redirect file url to another page in .htaccess

我需要將所有 php 文件從 url 末尾重定向到特定目錄,例如:

http://example.com/dir/file.php 
http://example.com/dir/folder/file.php 
http://example.com/dir/folder/folder2/file.php

http://example.com/dir2/file.php

我的代碼是

RewriteRule ^(.*).php$ http://example.com/dir2/$1.php [R=301,L]

但我得到

http://example.com/dir2//dir/file.php

您可以使用以下內容:

RewriteRule ^.*/?([^/.]+).php$ http://example.com/dir2/$1.php [R=301,L]

這只會在正則表達式而不是目錄中捕獲/file.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM