如何使用 .htaccess 操作 url 以使下面的 url 作業并縮短大小?
我成功地從 url 中洗掉了 .php、.html 擴展名,但不知道如何操作字符位置和洗掉查詢變數名稱。
Example:
www.website.com/blog?language=en-us
to:
www.website.com/en-us/blog
RewriteEngine On
DirectoryIndex index.php
ErrorDocument 404 /public_html/404.php
ErrorDocument 500 /public_html/500.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.] )$ $1.php [NC,L]
RewriteRule ^([^\.] )$ $1.html [NC,L]
uj5u.com熱心網友回復:
使用您顯示的示例,請嘗試遵循 htaccess 規則檔案。請確保在測驗您的 URL 之前清除您的瀏覽器快取。
RewriteEngine ON
##External redirect 301.
RewriteCond %{THE_REQUEST} \s/(blog)\?language=(\S )\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Internal rewrite to index.php file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/(.*)/?$ index.php?param1=$1&language=$2 [QSA,NC,L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/459209.html
