如何从附加的链接给url停止mod_rewrite的? [英] How do I stop mod_rewrite from appending links to url?

查看:178
本文介绍了如何从附加的链接给url停止mod_rewrite的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期望的答案将是这么简单的东西我就想哭,但我似乎无法弄清楚。我是新来的mod_rewrite的。

I expect the answer is going to be something so simple I'll want to cry, but I can't seem to figure it out. I'm new to mod_rewrite.

我想改变的东西从我的链接像domain.com/?p=about到domain.com/about*/*~~V(带斜线),并能正常工作,但每当我移动到一个链接,其追加到URL后面的新的链接。例如,我有一个关于与联系人联系。如果我点击一下导航到domain.com/about/~~V那么如果我点击的接触,它定位到domain.com/about/contact/~~V,将不断增加的URL的末尾的链接。如果我在domain.com,然后点击链接(约,在这种情况下),它会去domain.com/about/~~V,如果我按约4倍,我的地址栏会说domain.com/约/约/约/约/约/我在下面一个很简单的例子转载此,我究竟做错了什么?

I wanted to change my links from things like domain.com/?p=about to domain.com/about*/* (with the trailing slash) and it works fine, but whenever I move on to a link, it appends the new link to the back of the url. For example, I have an about and a contact link. If I click about it navigates to domain.com/about/ then if I click contact, it navigates to domain.com/about/contact/ and will keep adding the links to the end of the url. If I'm at domain.com and click a link(about, in this case) it will go to domain.com/about/ and if I click about 4 more times, my address bar is going to say "domain.com/about/about/about/about/about/" I have reproduced this in a very simple example below, what am I doing wrong?

的.htaccess

.htaccess

RewriteEngine On
RewriteRule ([a-zA-Z0-9]+)/$ index.php?p=$1

的index.php

index.php

<a href="about/">about</a> | <a href="contact/">contact</a><br><br>

<?php
    if(!isset($_GET['p'])) {
        echo "home";
    } else {
        echo $_GET['p'];
    }
?>

感谢您的帮助!

编辑: 它的工作原理好,如果我使用绝对路径,但我宁愿没有,如果我没有绝对要。

edit: It works okay if I use an absolute path, but I'd rather not if I don't absolutely have to.

EDIT2:添加

RewriteBase /

断开的链接。他们似乎是要domain.com/about/~~V和... /联系人/,但我得到一个404 - 我假设我用的规则是我在做链接的方式不知何故不兼容,这是为什么我包括的index.php为好。

breaks the links. They appear to be going to domain.com/about/ and .../contact/, but I get a 404 - I'm assuming the rule I used is somehow incompatible with the way I'm doing my linking, which is why I included index.php as well.

推荐答案

您正在定义所有的HTML中相对链接到当前路径。

You are defining all of your links in HTML relative to the current path.

您需要改变你的链接,这样:

You will need to change your links such that:

<a href="about/">about</a> | <a href="contact/">contact</a><br><br>

成为(注意前/中的URL):

becomes (note the leading / on the urls):

<a href="/about/">about</a> | <a href="/contact/">contact</a><br><br>

当你在页面上 site.com/about/us ℃的链接; A HREF =家用/获取由浏览器解析为 site.com/about/us/home

When you are on a page site.com/about/us a link like <a href="home/" gets resolved by the browser to be site.com/about/us/home.

解决的办法是改变所有的链接,图片,样式表和JavaScript脚本的使用绝对路径在你的网址,而非相对喜欢你了。

The solution is to change all of your links, images, stylesheets, and javascripts to use absolute paths in your URLs, not relative ones like you have now.

编辑:只注意到你的编辑。你真的应该使用绝对路径,而不是相对的。如果你想保持相对URL,那么你将不得不使用类似&LT;基地的HREF =//&GT; 在所有的页面的

Just noticed your edit. You really should use absolute paths, not relative ones. If you want to keep the relative URLs then you will have to use something like <base href="/" /> on all of your pages.

这篇关于如何从附加的链接给url停止mod_rewrite的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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