我有以下設置:從一個子目錄重寫網頁
index.php
config.php
pages/
index.php
about.php
contact.php
當我想訪問「about.php」,我需要訪問http://host.com/index.php?page=about
現在我想重寫URL等等它看起來像這樣:http://host.com/about.php
.htaccess應該怎麼看?我是mod_rewrite的完整noob。
我有以下設置:從一個子目錄重寫網頁
index.php
config.php
pages/
index.php
about.php
contact.php
當我想訪問「about.php」,我需要訪問http://host.com/index.php?page=about
現在我想重寫URL等等它看起來像這樣:http://host.com/about.php
.htaccess應該怎麼看?我是mod_rewrite的完整noob。
這應該爲你工作:
RewriteEngine On
#External redirect with THE_REQUEST trick; change R to R=301 when everything works correctly
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index\.php\?page=(.*)\ HTTP
RewriteRule^/%2.php\? [R=302,L]
#Internal rewrite
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*).php$ /index.php?page=$1 [L]
如果您訪問http://example.com/index.php?page=about
將您重定向到http://example.com/about.php
我試着像「重寫規則^頁/([^ /] *)\ PHP $的東西。 ?page = $ 1 [L]「 – iCON