重定向使用htaccess的文件重定向、文件、htaccess

2023-09-02 11:26:02 作者:睜著眼,說瞎話

编辑:

我要重定向的URL

www.example.com/location/sydney

从: www.example.com/rss.php?pickup=sydney

问题是我不能让$ _GET ['皮卡']值从www.example.com/location/sydney也位置也随之改变,例如:它可能是凯恩斯,伦敦等我有一个名为RSS文件。 PHP中,我将得到$ _GET ['皮卡']的值。 我想这一点: - 重定向/位置http://deals.vroomvroomvroom.com.au/rss.php

Problem is i cant get $_GET['pickup'] value from www.example.com/location/sydney and also location will also change for eg: it may be cairns,london etc. I have a file called rss.php in that i will get the value from $_GET['pickup']. I tried this :- Redirect /location http://deals.vroomvroomvroom.com.au/rss.php

但它给了我一个网址: - http://deals.vroomvroomvroom.com.au/rss.php/sydney 当我输入的网址 www.example.com/location/sydney

but it gives me a url :- http://deals.vroomvroomvroom.com.au/rss.php/sydney when i type in the url www.example.com/location/sydney

推荐答案

将一个.htaccess文件在以下位置的目录:

Place an .htaccess file in the location directory with the following:

RewriteEngine On
RewriteRule (.*) ../index.php?location=$1&e=1 [L,QSA]

这假定您要使用的请求/位置位于上方的位置目录的目录

This assumes that the index.php that you want to use for requests to /location is located in the directory above the location directory

如果您还需要重定向( www.abc.com/?location=sydney www.abc.com/location/sydney )工作,那么我想做到这一点的最好办法是添加以下到位于DocumentRoot中(单独).htaccess文件:

If you also need the redirect (www.abc.com/?location=sydney to www.abc.com/location/sydney) to work then I think the best way to do that is to add the following to the (separate) .htaccess file located in the DocumentRoot:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)location=([^&]*)(.*) [NC]
RewriteCond %{QUERY_STRING} !&e=1 [NC]
RewriteRule ^(.*)$ $1/location/%2?%1%3 [R=301,L,NE]