-4

Possible Duplicate:
How to redirect all requests to index.php and keep the other GET params?
Rerouting all php requests through index.php

Suppose we have /var/www/someapp/index.php script. Now, how can we make Apache server send all of the requests for URLS like

 http://somedomain.info/someapp/alpha
 http://somedomain.info/someapp/beta
 http://somedomain.info/someapp/beta/gamma
 http://somedomain.info/someapp/epsilon/omega

...to that very index.php script, and how can we retrieve the full path from inside that PHP script?

Community
  • 1
  • 1
Septagram
  • 9,425
  • 13
  • 50
  • 81
  • Please see the [StackOverflow FAQ](http://stackoverflow.com/faq), Specifically the section about [what not to ask](http://stackoverflow.com/faq/#dontask), namely: *"If you can imagine an entire book that answers your question, you’re asking too much."* – orourkek Aug 15 '12 at 22:27
  • 3
    Also, this is a duplicate of [this](http://stackoverflow.com/questions/9694118/rerouting-all-php-requests-through-index-php), [this](http://stackoverflow.com/questions/3776714/htaccess-rewriting-all-requests-to-a-single-controller?rq=1), [this](http://stackoverflow.com/questions/5214502/how-to-redirect-all-requests-to-index-php-and-keep-the-other-get-params), and [this](http://stackoverflow.com/questions/2669258/redirect-everything-to-index-php), to name *just a few*... – orourkek Aug 15 '12 at 22:30
  • 2
    [here's dozens more dupes](https://www.google.com/search?q=site%3Astackoverflow.com+redirect+~all+~subdirectory+to+~single+file), if anyone's interested. – orourkek Aug 15 '12 at 22:40

1 Answers1

1

Typically this is done via rewrite rules (i.e. mod_rewrite on Apache). So for Apache that might involve modifying the conf file for the host, or applying the following in an .htaccess file in the web root (assuming the host config allows for such override)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d    
RewriteRule ^someapp/(.*)$ /someapp/index.php?q=$1 [L]

This would redirect the request to the index.php file (without changing the URL in the browser's location bar) and pass the query portion after 'someapp/' as parameter 'q' via GET to be made available in to the script, so long as the URI does not match an actual file or directory.

Mike Brant
  • 70,514
  • 10
  • 99
  • 103
  • 3
    4k rep and you can't recognize a dupe? (it's actually a dupe of a dupe of a dupe of a dupe of a ...) – orourkek Aug 15 '12 at 22:32
  • @orourkek Certainly redirection topics exist in multiple places. This particular one however doesn't deal with redirecting ALL requests to index.php, but rather requests on a specific subdirectory. That is really the reason I answered it. – Mike Brant Aug 15 '12 at 22:35
  • 2
    Really? Instead of linking to the dozens of questions that answer to that specificity as well, [here's a large list of them](http://bit.ly/SoDrP1). *still a major dupe*, and very easy to find the answer, if the OP had even tried to look. – orourkek Aug 15 '12 at 22:39