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

3
  • Please see the StackOverflow FAQ, Specifically the section about what not to ask, namely: "If you can imagine an entire book that answers your question, you’re asking too much." Commented Aug 15, 2012 at 22:27
  • 3
    Also, this is a duplicate of this, this, this, and this, to name just a few... Commented Aug 15, 2012 at 22:30
  • 2
    here's dozens more dupes, if anyone's interested. Commented Aug 15, 2012 at 22:40

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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 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.
Really? Instead of linking to the dozens of questions that answer to that specificity as well, here's a large list of them. still a major dupe, and very easy to find the answer, if the OP had even tried to look.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.