views:

127

answers:

3

On of my client asked me to create an Web App in PHP, I ended up using Symfony. At delivery, he told me that he has distributed a software with an embedded Web view pointing to a hardcoded url :

www.domain.com/dir/tools.php

Now he wants the Web app to appear in it's Web View, but the software isused by about 400 customers, we can't expect the hard coded URL to be changed.

How do you think I can do that in clean way :

  • Create www.domain.com/dir/tools.php and use a redirection ? Which one and how ?
  • Use URL rewriting ? Any snippets appreciated, I have no Idea how to do that.
+8  A: 

Apache mod_rewrite:

RewriteEngine on
RewriteRule   ^dir/tools\.php$   new_page.php   [R=301]

EDIT: As noted, this goes in your .htaccess file. The mod_rewrite documentation I linked has more information. Fixed .

Matthew Flaschen
+1 for answer ... and reading the question right through (more than I did :P )
Aiden Bell
It sounds interesting. Why is that better that setting a redirect with header('Location: mapage.php') in tools.php. In Which file am I supposed to put it and with tag ?
e-satis
@e-satis - it is quicker because apache compiles the expression and doesn't need to invoke PHP. Put it under a <directory> directive in the vhost or just in the vhost main body.
Aiden Bell
That will work if used in .htaccess. If put on main config it'll need a / after the ^.
Vinko Vrsalovic
Don’t forget to escape the dot.
Gumbo
A: 

Use URL rewriting.

URL rewriting is implemented with a couple lines of configuration in your web server software. It is not implemented in your own web application, so you would not be using PHP to implement it. You will be telling your web server that any request that comes in asking for "/dir/tools.php" will be modified, before it ever hits your PHP web application, to ask for whatever URL you want it to ask for. For example, you can specify that any request asking for "/dir/tools.php" be rewritten to ask for "/my-custom-dir/my-tools/" instead.

Each web server implements URL rewriting differently. Often, the web server will not support that feature with a minimal out-of-the-box feature set, but through an addon that you can install. You should consult the documentation for your web server to find out how to configure it to perform URL rewriting.

Justice
+1  A: 

In your Apache configuration for the host or in a .htaccess file, you can do a redirect:

Redirect 301 /dir/tools.php http://www.example.com/whatever
Tom Haigh