[英]How can I redirect url in PHP using htaccess
我需要一些 URL 重寫規則
我想:
www.dawsonautodetailing.com/?page=About-Us
變成:
www.dawsonautodetailing.com/page/About-Us
或www.dawsonautodetailing.com/About-Us
我已經在我的根文件夾中創建了 .htaccess。
感謝您的幫助!
我試過用谷歌搜索,但由於我是 .htaccess 的新手,我什至不知道從哪里開始:)
您可以使用 Apache 中的 mod_rewrite 模塊使用 .htaccess 重定向 PHP 中的 URL。
要重定向特定的 URL,您可以在 .htaccess 文件中使用以下語法:
RewriteEngine On
RewriteRule ^old-url$ http://www.example.com/new-url [R=301,L]
這會將對 URL“old-url”的任何請求重定向到“http://www.example.com/new-url”,並使用“301”重定向(永久重定向)。
您還可以使用正則表達式來匹配 URL 中的模式並相應地重定向。 例如,如果要將所有以“old-directory”開頭的 URL 請求重定向到“new-directory”,可以使用以下方法:
RewriteEngine On
RewriteRule ^old-directory/(.*)$ http://www.example.com/new-directory/$1 [R=301,L]
這會將任何以“old-directory”開頭的 URL 重定向到相同的 URL,但以“new-directory”開頭。
修改 .htaccess 時要小心,因為它可能會導致網站出現故障。 在進行任何更改之前進行備份始終是一個好習慣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.