[英]htaccess tidy up url
因此,我一直在嘗試使自己的url看起來更好,但我無法使其按需運行,因此這里可能會有一些不錯的靈魂可以幫助我。
我需要幫助
例如:www.domain.com/project/index.php?p = settings&u = 123&l = k
看起來像www.domain.com/project/settings
我希望刪除index.php並刪除第一個變量之后的所有字符(在本例中為p = settings),還要刪除?p =
我現在知道了
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
旋轉一下。
RewriteRule ^project/([^/]*)$ /project/index.php?p=$1&u=123&l=k [L, QSA]
有重定向錯誤代碼的可能性
ErrorDocument 404 /index.php
這樣,您可以請求www.domain.com/project/settings
不存在,並且將錯誤404重定向到/index.php,而不是錯誤404。
$uri_asked = explode("/", $_SERVER['PHP_SELF']);
那你有
$uri_asked[3]="project";
$uri_asked[4]="settings";
你可以建立像
include("www.domain.com/index.php?p=".$uri_asked[3]."&u=".$uri_asked[4]);
您可以使用以下規則丟棄不需要的查詢字符串:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php\?p=([^&\s]+) [NC]
RewriteCond %{REQUEST_URI} !/system/ [NC]
RewriteRule ^(.*?)index\.php$ /$1%1? [R=301,NE,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.