1

I got these relative links in my phpbb forum which I'd like to replace with absolute links:

For example, in HTML the links are written like:

<a href="./viewforum.php?f=5">Bladiebla</a>
<a href="./memberlist.php?mode=viewprofile&u=63">Admin</a>

These are links on a domain calld e.g.: http:://www.foo.com

I'd like these links lead to another different domain:

http://www.example.org/viewforum.php?f=5
http://www.example.org/memberlist.php?mode=viewprofile&u=63

Is there any fast way of doing this using htaccess?

The htaccess should only account for /viewforum.php and /memberlist.php

(not site-wide!)


The problem is:

I have a forum on a subdomain (forum.example.com) which I scrape and show on the frontpage (example.com). Clicking the links in the scraped forum content however, because they are relative, lead me to places like: example.com/viewforum.php?f=5 (which does not excist) but I'd like them to lead to forum.example.com/viewforum.php?f=5... dunno if I'm clear enough..

dbc
  • 104,963
  • 20
  • 228
  • 340
Gerben
  • 61
  • 7

2 Answers2

1

No.

I'm almost completely certain that you can't using just .htaccess, and if you could, it would be an incredibly messy regular-expression based system that you want to avoid at all costs.

If you must change them, change them manually1 because if you end up doing it with a .htaccess file it will be a complete waste of processing power, too.


1 Obviously, this doesn't actually have to be completely manual. You can do find and replace stuff - make sure to check the results, though. If the URL will change, then consider outputting it dynamically with PHP instead. Also, just drop the ./ part because it's useless.

Community
  • 1
  • 1
Ry-
  • 218,210
  • 55
  • 464
  • 476
  • The problem is: I have a forum on a subdomain (forum.example.com) which I scrape and show on the frontpage (example.com). Clicking the links in the scraped forum content however, because they are relative, lead me to places like: example.com/viewforum.php?f=5 (which does not excist) but I'd like them to lead to forum.example.com/viewforum.php?f=5... dunno if I'm clear enough.. – Gerben Jan 01 '12 at 21:43
  • @Gerben: Do you scrape them with PHP? – Ry- Jan 01 '12 at 21:55
  • Yes that's correct, I use simplehtmldom for that and simply output the html. – Gerben Jan 01 '12 at 22:13
  • @Gerben: So get all the links and replace `./viewforum.php` and `./memberlist.php` with `http://forum.example.com/viewforum.php` and `http://forum.example.com/memberlist.php`, respectively. – Ry- Jan 01 '12 at 22:21
  • Totally forgot that option, I'll try doing that! Didn't came up to my mind. Accepted your answer, sorry I can't vote up. – Gerben Jan 01 '12 at 22:32
0

You cannot use .htaccess file to change the HTML code.

  • Hmm I see, can it atleast be redirected? So pressing: Bladiebla Would lead to: http://www.example.org/viewforum.php?f=5 – Gerben Jan 01 '12 at 21:36
  • You might be able to redirect, but I don't think you should do that way because one it would be kind of messy and two you are now making an extra redirect which can be easily avoided by changing your HTML code. –  Jan 01 '12 at 21:40