2011-02-23 29 views
0

我试图从[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] 

回答

0

不是很清楚,这是你在找什么?

RewriteRule ^([^-]+)--(.+)$ /state/$1--$2/index.php 
+0

不太我会尽量让更多的细节。例如,我在我的网站上有这样的链接[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

+0

然后我给出的应该完全一样:) – adarshr 2011-02-23 11:20:04

+0

对不起,没有工作:我得到一个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

1
RewriteRule ^(.*)--(.*)$ /state/$1--$2/index.php&%{QUERY_STRING} [L]