我試圖從[http://test.site.com/ pagename - city /]這樣的請求重定向到[http:// test .site.com/state/pagename - city /],然後回到[http://test.site.com/pagename-city/]。 'state/pagename - city'是服務器上的物理目錄。所以如果有人點擊[http://test.site.com/pagename-city/]我需要執行[http://test.site.com/state/pagename-city/index.php],但是要保留的網址[http://test.site.com/pagename-city/]。任何幫助讚賞。日Thnx。.htaccess重寫從請求中刪除目錄名
.htaccess文件
Options +FollowSymlinks
RewriteEngine On
RewriteBase/
RewriteCond %{REQUEST_URI} /(.*)--(.*)/?$
RewriteCond %{REQUEST_URI} !/state/
RewriteRule .* http://%{HTTP_HOST}/state%{REQUEST_URI} [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* page.php?&[|]v1||%{REQUEST_URI}[|]v2||-[|]v3||%{HTTP_HOST}[|]v4||%{REQUEST_FILENAME}[|]v5||EOL[~|~]= [QSA,L]
不太我會盡量讓更多的細節。例如,我在我的網站上有這樣的鏈接[http://test.site.com/pagename-city/],但在服務器上有一個物理目錄結構,比如/ state/pagename - city。當你點擊[http://test.site.com/pagename-city/]我想請求[http://test.site.com/state/pagename-city/index.php],但URL保持這樣[http://test.site.com/pagename-city/] – adrian 2011-02-23 11:17:58
然後我給出的應該完全一樣:) – adarshr 2011-02-23 11:20:04
對不起,沒有工作:我得到一個500錯誤。這是我的.htaccess文件'選項+的FollowSymLinks RewriteEngine敘述在 RewriteBase/ 的RewriteCond%{REQUEST_URI}^/(。*) - (。*)?/ $ 重寫規則^(+) - ( 。+)$ /state/$1--$2/index.php [L] 的RewriteCond%{REQUEST_FILENAME}!-d 的RewriteCond%{REQUEST_FILENAME}!-f 的RewriteCond%{REQUEST_FILENAME}!-l 重寫規則。* page.php?&[|] v1 ||%{REQUEST_URI} [|] v2 || - [|] v3 ||%{HTTP_HOST} [|] v4 ||%{REQUEST_FILENAME} [|] v5 || EOL [〜|〜] = [QSA,L]' – adrian 2011-02-23 11:49:56