0

As the title says, I want all requests

domain.com/something
domain.com/somethting/else
domain.com/a/third/thing

to redirect to

domain.com

BUT still show the original URL since I want to use them as parameters. I've tried these two ideas but the URLs end up displaying

domain.com
Community
  • 1
  • 1
Daniel
  • 2,435
  • 5
  • 26
  • 40

1 Answers1

0

I found the answer here at Gareth Jones's blog:

Passing all requests to a single PHP script

I needed all requests with a certain URL prefix to be handled by a single script. This was easily solved using the following URL re-writing rule in a .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^.*$ index.php

Note that I had to enable the mod_rewrite module in Apache and ensure that directives could be overridden with the following:

<Directory /var/www/>
  AllowOverride All
</Directory>

Determining the full requested URL

Another requirement of my application complicated by URL rewriting was that I needed access to the full URL. I achieved this with the following bit of code:

$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
$location = $_SERVER['REQUEST_URI'];
if ($_SERVER['QUERY_STRING']) {
  $location = substr($location, 0, strrpos($location, $_SERVER['QUERY_STRING']) - 1);
}
$url = $protocol.'://'.$_SERVER['HTTP_HOST'].$location;
Daniel
  • 2,435
  • 5
  • 26
  • 40