改写为本地主机和现场envoirement规则 [英] Rewrite rules for localhost AND live envoirement

查看:98
本文介绍了改写为本地主机和现场envoirement规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加规则集,在当地环境(本地)和我liveserver工作。

I want to add rewriterules that works in local environment (localhost) and on my liveserver.

为什么?

我不希望改变规则,当我在本地测试我的项目,并把它上传到liveserver。

I don't want to change rules when I test my project locally and upload it to the liveserver.

  1. 添加规则

下面的例子

(ANY-URL)index.php?page=somepage

更改

(ANY-URL)/somepage

所以,我用了一个rewritemod发电机和粘贴到这一点的:

So I used a rewritemod generator and pasted this into it:

index.php?page=somepage

我得到的重写规则,看起来是这样的:(当然我.htacces开始RewriteEngine叙述上)

The rewriterule I got, looks like this: (of course my .htacces starts with RewriteEngine On)

RewriteRule ^([^/]*)$ /?page=$1 [L]

当我试着去(HTTP :) //localhost/myproject/development/index.php?page=login 发送我的我的地方发展envirment的根目录下。但在adressline URL不改变。

When I try to get to (http:) //localhost/myproject/development/index.php?page=login it sends me to the root directory of my local development envirment. But the URL in the adressline doesn't change.

测试

当然,我尝试了一些其他的规则粘贴整个网址到发电机只是为了测试,如果重写的东西的作品。 而且,这里的URL不会更改为短网址,但服务器无法找到样式表和JavaScript脚本了。我被重定向到的index.php

Of course I tried some other Rules by pasting the whole URL into the generator just to test if the rewrite thing works. Also here the URL doesn't change to short-url but the server cant find stylesheets and javascripts anymore. I got redirected to the index.php

可能的解决方案?

  • 也许有一些待办事项与的RewriteBase?
  • 请我一定要设置一个basepath?

我的.htacces位于:

My .htacces is located here:

//localhost/myproject/development/.htaccess

后来我也想改变这种看起来像这样的路径:

Later I also want to change paths that look like this:

(ANY-URL)index.php?page=somepage&second=hello&third=world&fourth=cool

另外这里我正在寻找一个解决方案,在两个环境中工作。

Also here a I'm looking for a solution that works on both environments.

推荐答案

由于htaccess是位于子目录里面,使用的RewriteBase

Since the htaccess is located inside a sub-directory, use RewriteBase:

RewriteEngine On
RewriteBase /myproject/development/

一旦做到这一点,您可以使用基础元素在你的PHP / HTML文件。这将解决您的网页脚本/样式表的地址。

Once that is done, you use the base element in your php/html files. This will resolve the addresses for the scripts/stylesheets in your pages.

<base href="/myproject/development/" />

现在,在htaccess的重写的将是:

Now, the rewrites in htaccess would be:

RewriteRule ^((?!index\.php)[^/]+)/?$ index.php?page=$1 [L]

这篇关于改写为本地主机和现场envoirement规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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