重定向使用htaccess的文件 [英] redirect using htaccess file

查看:261
本文介绍了重定向使用htaccess的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:

我要重定向的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]

这篇关于重定向使用htaccess的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆