简体   繁体   English

.htaccess重写从请求中删除目录名称

[英].htaccess rewrite remove directory name from request

I am trying to make a redirect from a request like [http://test.site.com/ pagename--city /] to something like [http://test.site.com/ state/pagename--city /] and then back to [http://test.site.com/pagename--city/]. 我正在尝试从[http://test.site.com/ pagename--city /]之类的请求重定向到[http://test.site.com/ state / pagename--city /]之类的请求然后返回[http://test.site.com/pagename--city/]。 The 'state/pagename--city' are physical directories on the server. “状态/页面名称-城市”是服务器上的物理目录。 So if someone clicks on [http://test.site.com/pagename--city/] I need to execute [http://test.site.com/state/pagename--city/index.php] but the URL to remain [http://test.site.com/pagename--city/]. 因此,如果有人点击[http://test.site.com/pagename--city/],我需要执行[http://test.site.com/state/pagename--city/index.php],但是保留的网址[http://test.site.com/pagename--city/]。 Any help appreciated. 任何帮助表示赞赏。 Thnx. 谢谢

.htaccess file .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]
RewriteRule ^(.*)--(.*)$ /state/$1--$2/index.php&%{QUERY_STRING} [L]

不是很清楚,这是您要找的东西吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM