PDA

View Full Version : htaccess (is this possible)



itivae
01-08-2013, 12:38 AM
I know its possible to use htaccess for a 301 redirect such as
/olddirectory/oldfile.html http://yoursite.com/newdirectory/newfile.html
Is it possible to redirect say when a call such as
action or
href ie
form action="myfile.php" to form action="myfile2.php"

Is there perhaps a better way to do this? Any help or advice would be appreciated.

Thanks

traq
01-08-2013, 02:16 AM
The fact that a request was triggered by an "action" or "href" attribute is not available to the server.
However, you can have a rewrite rule for such a page, just like any other:
RewriteEngine On
RewriteRule myfile.php myfile2.php

VBAssassin
01-08-2013, 02:00 PM
May i ask why you are interested in doing this? Since there may be a better way for you to solve this problem.

itivae
01-08-2013, 09:14 PM
I have some work to do on a .html site. The Search Bar is coded into every page. If I change the action I dont want to recode every page to reflect these changes.

Beverleyh
01-08-2013, 10:33 PM
traq's htaccess rewrite is the one that I'd go with in this case then.

As this is to fix your search form action, can you not edit the form action php page? That would be the obvious solution to this specific problem...

traq
01-09-2013, 03:27 AM
I have some work to do on a .html site. The Search Bar is coded into every page. If I change the action I dont want to recode every page to reflect these changes.

Actually (while the rewrite I suggested will work just fine), I'd say editing the HTML is the preferable choice (unless it's a temporary change). The redirect will incur overhead (which may not be noticable, but whatever). Additionally, your code would be much more understandable. Just search+replace every instance of action="myfile.php" with action="myfile2.php".

While you're at it, if you're using PHP anyway, you might want to remove the search bar HTML entirely and place it in a separate file (which you can then include (http://php.net/include) on each page) - it would make changes like these much simpler in the future.