Mik2000dk
Mik2000dk

Reputation: 31

htaccess rewrite absolute link folder

I have used htaccess to rewrite my links on my page

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 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/

But then my pages dosent work, since all my links are absolute, and dont have /test/ in front


Is it somehow possible to make all links have /test/ in front for example using htaccess file (without interrupt my other rules)?

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. 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

Upvotes: 1

Views: 450

Answers (1)

anubhava
anubhava

Reputation: 785651

Option 1:

Try this rule in your DOCUMENT_ROOT/.htaccess file:

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

Option 2: You can try adding this in your page's header:

<base href="/test/" />

Upvotes: 1

Related Questions