简体   繁体   English

htaccess重写绝对链接文件夹

[英]htaccess rewrite absolute link folder

I have used htaccess to rewrite my links on my page 我已使用htaccess重写页面上的链接

RewriteEngine On
RewriteRule ^search/([^&]+)$ search.php?q=$1 [L]
RewriteRule ^login/?$ login.php [L]
# etc..

On my PHP pages I have made all my links absolute like this 在我的PHP页面上,我已经使所有链接都绝对是这样的

<?php require("/incl_head.php"); ?>
<link href="/css/css_file.css" rel="stylesheet" type="text/css">
<img src="/images/image.jpg">

This works fine locally, but now I want to test it online, and I have to put it into a subfolder, since my old page is still active. 这在本地可以正常工作,但是现在我想在线对其进行测试,并且由于我的旧页面仍然处于活动状态,因此必须将其放入子文件夹中。 My subfolder will be test so that my domain will be www.mydomain.dk/test/ 我的子文件夹将被测试,因此我的域名将是www.mydomain.dk/test/

But then my pages dosent work, since all my links are absolute, and dont have /test/ in front 但是然后我的页面就起作用了,因为我所有的链接都是绝对的,并且前面没有/ test /


Is it somehow possible to make all links have /test/ in front for example using htaccess file (without interrupt my other rules)? 是否有可能使所有链接都位于/ test /前面,例如使用htaccess文件(不中断我的其他规则)?

Or what should I do? 或者我该怎么办?

Have seen some html base possibilities or some where they save root in vaiable and include in front of all links. 看到了一些html基础的可能性,或者它们在其中保存根目录并包含在所有链接前面的位置。 But if I add that into a file and tries to include it, I would have the same problem with those includes on every page. 但是,如果我将其添加到文件中并尝试包含它,则每个页面上的包含文件都会遇到相同的问题。

Hope someone can help me 希望可以有人帮帮我

Option 1: 选项1:

Try this rule in your DOCUMENT_ROOT/.htaccess file: 在您的DOCUMENT_ROOT/.htaccess文件中尝试以下规则:

RewriteRule !^test/ /test%{REQUEST_URI} [L,NC,R]

Option 2: You can try adding this in your page's header: 选项2:您可以尝试将其添加到页面标题中:

<base href="/test/" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM