久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何阻止 mod_rewrite 將鏈接附加到 url?

How do I stop mod_rewrite from appending links to url?(如何阻止 mod_rewrite 將鏈接附加到 url?)
本文介紹了如何阻止 mod_rewrite 將鏈接附加到 url?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我希望答案很簡(jiǎn)單,我會(huì)想哭,但我似乎無(wú)法弄清楚.我是 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*/*(帶有尾部斜杠)并且它工作正常,但是每當(dāng)我轉(zhuǎn)到鏈接,它將新鏈接附加到 url 的后面.例如,我有一個(gè)關(guān)于和聯(lián)系鏈接.如果我點(diǎn)擊關(guān)于它導(dǎo)航到 domain.com/about/然后如果我點(diǎn)擊聯(lián)系人,它導(dǎo)航到 domain.com/about/contact/并將繼續(xù)添加鏈接到 url 的末尾.如果我在 domain.com 并單擊一個(gè)鏈接(在這種情況下是關(guān)于),它將轉(zhuǎn)到 domain.com/about/,如果我再單擊大約 4 次,我的地址欄將顯示domain.com/about/about/about/about/about/" 我在下面的一個(gè)非常簡(jiǎn)單的例子中復(fù)制了這個(gè),我做錯(cuò)了什么?

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

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

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'];
    }
?>

感謝您的幫助!

如果我使用絕對(duì)路徑,它可以正常工作,但如果我不是絕對(duì)必須,我寧愿不要.

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

edit2:添加

RewriteBase /

斷開(kāi)鏈接.他們似乎要去 domain.com/about/和 .../contact/,但我得到 404 - 我假設(shè)我使用的規(guī)則在某種程度上與我進(jìn)行鏈接的方式不兼容,這就是為什么我也包括 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.

推薦答案

您正在定義相對(duì)于當(dāng)前路徑的 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>

成為(注意網(wǎng)址上的前導(dǎo)/):

becomes (note the leading / on the urls):

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

當(dāng)您在頁(yè)面 site.com/about/us 上時(shí),瀏覽器將像 <a href="home/" 這樣的鏈接解析為 <代碼>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,以在網(wǎng)址中使用絕對(duì)路徑,而不是像現(xiàn)在這樣使用相對(duì)路徑.

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.

剛剛注意到您的編輯.你真的應(yīng)該使用絕對(duì)路徑,而不是相對(duì)路徑.如果您想保留相對(duì) URL,則必須在所有頁(yè)面上使用類(lèi)似 <base href="/"/> 的內(nèi)容.

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.

這篇關(guān)于如何阻止 mod_rewrite 將鏈接附加到 url?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動(dòng)作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類(lèi)/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問(wèn)?) - IT屋-程序員軟件開(kāi)發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個(gè)網(wǎng)站的單一入口點(diǎn).壞的?好的?沒(méi)問(wèn)題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務(wù)層在 Zend 或 PHP 中常見(jiàn)嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 亚洲欧美精品久久 | 日本三级电影在线看 | 国产精品久久久久久久久久久新郎 | 亚洲每日更新 | 成人久久网| 亚洲国产精品日本 | 成人二区| 99欧美精品 | 日韩在线视频免费观看 | 在线激情视频 | 一区二区三区四区在线 | 久久久青草婷婷精品综合日韩 | 欧美精品一区二区三区蜜桃视频 | 中文字幕成人av | av香蕉| 一区二区三区四区视频 | 99re在线视频 | 久久国产成人午夜av影院武则天 | 99精品电影 | 国产视频精品在线 | 一区二区影院 | 日韩手机视频 | 岛国av一区二区三区 | 欧美日韩综合精品 | 国产精品视频久久久 | 亚洲黄色一区二区三区 | 久久av网站 | 久久久久久久久91 | 久久久久久国产精品免费免费狐狸 | 小早川怜子xxxxaⅴ在线 | 操夜夜| 爱操影视 | 欧美福利视频一区 | 欧美大片黄 | 日韩一区二区免费视频 | 天天操天天插 | 在线观看黄色电影 | 亚洲精品中文字幕在线观看 | 欧美日韩国产高清 | 99在线免费观看视频 | 亚洲精品视频免费 |