在localhost中重定向的URL

时间:2013-11-11 07:47:04

标签: php apache

我正在使用一个简单的htaccess文件来重写我的项目的网址。我在一个get变量中重写了整个url,然后用php来解析它。

我的问题是当我尝试发送重定向标头时,我似乎无法正确使用它。

例如,假设我正在查看页面

localhost/myProject/home

带标题

header('Location: login');

重定向到

localhost/myProject/home/login

当我尝试

 header('Location: /login');

它需要我

localhost/login 

不存在,我收到404错误。

到目前为止,我找到工作的唯一方法就是当我做

header('Location: http://localhost/myProject/login');

但我不认为这是一个不错的选择,因为当我的网站上线时,我将不得不改变每一个标题。

有更好的方法吗?

我的.htacces文件是:

RewriteEngine On 
RewriteBase /myProject/

#Make sure it's not an actual file 
RewriteCond %{REQUEST_FILENAME} !-f

#Make sure its not a directory 
RewriteCond %{REQUEST_FILENAME} !-d 

#Rewrite the request to index.php 
RewriteRule ^(.*)$ index.php?get=$1 [L]

1 个答案:

答案 0 :(得分:1)

你可以这样做:使用base url变量。定义变量global或config文件。你只需要改变一次该变量:

$base_url = "http://google.com"; or define('base_url', 'http://google.com');
相关问题