簡體   English   中英

PHP 中查詢字符串的 HTACCESS 重寫規則

[英]HTACCESS Rewrite Rule for Query String in PHP

我有我的 URL https://example.com/?hfgshdsds

我需要重寫一個規則,即使我刪除了問號,鏈接也會像以前一樣工作,所以我的 url 需要是https://example.com/hfgshdsds

目前在我的 .htaccess 文件中,我只有打開不帶擴展名的 php 的規則。php。

RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

謝謝!

使用您顯示的示例,請嘗試遵循 htaccess 規則文件。 請確保在測試您的 URL 之前清除您的瀏覽器緩存。

RewriteEngine On
##keep redirection Rules first then keep rest of rules.
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php/?$ %{REQUEST_FILENAME}.php [QSA,L]

##Adding new rule here for non-existing pages here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?$1 [QSA,L]

暫無
暫無

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

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