[英].htaccess Remove index.php remove query and leave string
我一直在處理.htaccess文件。 我開始使用的網址是www.example.com/index.php?page=pagetitle
。 我希望鏈接僅顯示www.example.com/pagetitle
。
到目前為止,我的.htaccess文件中唯一的內容是刪除了index.php
。
Options -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.(php|html?)
RewriteRule ^ /%1 [R=301,L]
任何幫助將不勝感激,可悲的是,我不具備自己創建這些代碼的知識。
先感謝您。
我還將在其他人的支持下(如我所想)進一步編輯該問題。
您可以嘗試以下規則:
Options -MultiViews
RewriteEngine on
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.