我正在嘗試重寫規則并且已經卡住了這么久。
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page\=about$
RewriteRule ^$ /about? [L]
我想要實作的是:
從
https://localhost/site/
https://localhost/site/?page=about
https://localhost/site/?page=food
https://localhost/site/?page=place
https://localhost/site/?page=shop
https://localhost/site/?page=place&area=west
到
https://localhost/site/
https://localhost/site/about
https://localhost/site/food
https://localhost/site/place
https://localhost/site/shop
https://localhost/site/place/west
每當我嘗試使用我的本地主機或我的域(頂級域:www.mydomain.com)時,我都會收到:
Internal Server Error
編輯:現在我有以下代碼。沒有錯誤。
RewriteEngine on
#1) redirect the client from "/index.php/foo/bar" to "/foo/bar"
RewriteCond %{THE_REQUEST} /index\.php/(. )\sHTTP [NC]
RewriteRule ^ /%1 [NE,L,R]
#2)internally map "/foo/bar" to "/index.php/foo/bar"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(. )$ /index.php?page=/$1 [L]
沒有錯誤,但如果我去 https://localhost/site/about 它會將我重定向到主頁內容,即使 URL 是 https://localhost/site/about
但是在實時站點www.mysite.com 上,它幾乎可以完美運行。
www.mysite.com/about √ works
www.mysite.com/shop √ works
www.mysite.com/place/west x not working
由于我從另一個來源復制了這個,評論說#2)在內部將“/foo/bar”映射到“/index.php/foo/bar”。
-如何將此映射到 index.php?page=about?
- 如何使其適用于www.mysite.com/place/west?
uj5u.com熱心網友回復:
您可以使用以下規則:
RewriteEngine On
#Redirect /site/?page=foobar to /site/foobar
RewriteCond %{THE_REQUEST} /site/(?:index\.php)?\?page=(. )\sHTTP [NC]
RewriteRule ^ /site/%1? [L,R]
# Internally rewrite new path to the original one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?:site/)?(. )/?$ /site/?page=$1 [L,QSA]
我還沒有測驗過,但我相信它應該適用于您的網址。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/350140.html
