1

Trying to make a website more search engine friendly, have done some readning that routing with .htaccess is a good way to go.

I have a path called: mydomain.net/forum Under there I have category, items and posts.

I whould like to have mydomain.net/forum/boats/laws/this-is-a-post-about-laws

In .htaccess I have tried:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule forum/^(.*)$ forum/index.php?page=$1 [L,QSA]

In my file/forum.php

$route = explode('/',$_GET['page']);

$sidepage    = isset($route[0]) ? $route[0] : null;
$kat = isset($route[1]) ? $route[1] : null;
$emne    = isset($route[2]) ? $route[2] : null;

Anyone could point me in the correct way to get this? Without affecting mydomain.net/index.php and the other sub-folders yet :)

MrKarlsen
  • 11
  • 4
  • "In my file/forum.php" - Although you reference `index.php` in your rule? So, `/forum` is a physical directory? `forum/^(.*)$` - what is the `^` doing? – MrWhite Jul 17 '22 at 23:53
  • Your life will probably be easier if you send all not-found files and directories to a router script, don’t special-case just the forums. It is way-easier for most people, myself included, to troubleshoot this in PHP instead of Apache. The performance impact is negligible to the point that you won’t notice (as long as you do it in a relatively sane way). – Chris Haas Jul 18 '22 at 01:19
  • What do you mean with not-found files and directories? If it's not a fysical file it will go to the router script? Is that possible? So if I have a file that is called /do-somethingelse.php it wil still load if I link to it directly? – MrKarlsen Jul 18 '22 at 06:41
  • See [this](https://stackoverflow.com/a/13612810/231316) or [this](https://stackoverflow.com/a/34981348/231316), both are very common patterns employed by pretty much every PHP framework these days – Chris Haas Jul 18 '22 at 12:15
  • "Is that possible?" - It's what the rule you posted is trying to do. Except that you've just messed by the regex and are rewriting to `index.php`, not `forum.php`. (?) – MrWhite Jul 18 '22 at 22:17

0 Answers0