[英]How to use 2 Passed Parameters to Change URL With htaccess?
假設我的網址看起來像:
localhost/category.php?id=name&phrase=something
我可以使用什么.htaccess重寫規則代碼來使其看起來像:
localhost/name/something
以下是我的.htaccess文件當前的外觀:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?article/([^/]*)$ /article.php?id=$1 [L]
RewriteRule ^/?wrestler/([^/]*)$ /wrestler.php?id=$1 [L]
# Removes the .php extension from pages
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
有什么想法嗎?
您可以使用以下規則:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# external redirect from /category.php?id=name&phrase=something to /name/something
RewriteCond %{THE_REQUEST} \s/+category\.php\?id=([^&]+)&phrase=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [R=302,L]
# skip files and directories from rewrites
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^/?article/([^/]+)/?$ article.php?id=$1 [L,QSA]
RewriteRule ^/?wrestler/([^/]+)/?$ wrestler.php?id=$1 [L,QSA]
# Removes the .php extension from pages
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^([^/]+)/([^/]+)/?$ category.php?id=$1&phrase=$2 [L,QSA]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.