Avatar of Valleriani
Valleriani
Flag for Sweden asked on

.htaccess manipulation of a link? (From name: StringA to StringB

Hello,

I have the following link, for example

http://test.com/index.php?browseto=campaignArea&page=1


Etc, very simple. What I want is .htaccess to make a certain word go to the same area. For example

http://test.com/index.php?ulink=broadcastArea&page=1
would be the same as
http://test.com/index.php?ulink=campaignArea&page=1

.. There is a problem with just changing it because of the structure the files were created in,. 'campaignArea' is actually a value that represents a mySQL value it searches for, and it's used in 'several' files statically. The simple idea I had instead of having to adjust more then 100 files would be to make 'broadcastArea' go to the same location as campaignArea if its in the link.

The thing is, I don't want the 'name' to be different. I can obviously make broadcastArea redirect to campaignArea first, but I want it so that the user sees:

'http://test.com/index.php?ulink=broadcastArea&page=1' still, but the server would see

'http://test.com/index.php?ulink=campaignArea&page=1' if that makes sense, which I hope .htaccess can actually do.

broadcastArea actually goes no where, but campaignArea would work, is the reason why, in a quick sense.


So to short form it, replace part of a string with another string, but the link should stay the same in the users browser, link manipulation/prettifying. Is this possible?
Apache Web ServerPHPWeb DevelopmentWeb Languages and Standards

Avatar of undefined
Last Comment
Valleriani

8/22/2022 - Mon
Valleriani

ASKER
I've tried something like

RewriteRule (.+)+(test)+(.+) $1test2$2 [R=301,L]

Which should change test to test2 anywhere, but  no luck.
Ray Paseur

Certainly it is possible and I would think that you would not want to directly rely on the contents of the request (URL arguments) to build the query string.  That smells like a security exposure to me, or at least a brittle design.

Here is how I would do it... Forget about URL rewriting and instead use a translation table that makes an intelligent interpretation of the contents of the $_GET['ulink'] parameter.  This has two effects.  First, it provides automatic filtering of the external (tainted) data.  Second, it makes for a design that decouples your data base queries from external data.

See http://www.laprbass.com/RAY_switch_example.php
<?php // RAY_switch_example.php
error_reporting(E_ALL);
echo "<pre>";


// DEMONSTRATE THE USE OF SWITCH / CASE CONDITIONAL LOGIC
// MAN PAGE HERE: http://php.net/manual/en/control-structures.switch.php
// NOTE THIS: "The switch statement is similar to a series of IF statements ON THE SAME EXPRESSION."


// IF ANYTHING POSTED
if (!empty($_GET["i"]))
{
    // GET THE POSTED DATA IN A LOCAL VAR
    $i = trim(strtoupper($_GET["i"]));

    // SWITCH ON THE BASIS OF THE CONTENTS OF OUR LOCAL VAR
    switch ($i)
    {
        case "A" :
        case "B" : echo "YOU ENTERED EITHER 'A' OR 'B' ";
                   $sql = "SELECT thing FROM table WHERE thing = 'AAA' OR thing = 'BBB'";
                   break;

        case "C" : echo "YOU ENTERED 'C' ";
                   $sql = "SELECT thing FROM table WHERE thing = 'CCC'";
                   break;

        default  : echo "YOU ENTERED NONE OF A, B OR C ";
                   $sql = "SELECT thing FROM table WHERE 1=1";
    }

    echo PHP_EOL;
    echo "THE RESOLVED QUERY SAYS: $sql";
}

// CREATE THE FORM FOR INPUT (OR JUST USE THE URL)
$form = <<<FORM
<form>
ENTER 'A' 'B' OR 'C'
<input name="i" />
<input type="submit" />
</form>
FORM;
echo $form;

Open in new window

Valleriani

ASKER
Yes, it pretty much is a 'hack' in a sense, I agree. The script itself is such a mess and just needs a minor name fix. The thing is though it's all over the place, it's wouldn't be one simple edit and its a bit of a problem because of it, specially because its kind of its own 'php' module in a sense.

The link itself actually runs with the script, so

http://test.com/campaignID=1 for example would mean that campaignID is an actual name of the mysql query. When grabbing from the system you actually don't call mysql directly, it's a 'form builder'.

At the moment, it's defined as campaignID, but since they changed the name to broadcastID, they want that simple value changed. The problem is, campaignID would have to be changed internally, in the MYSQL database because of how the form builder works (it uses it to save, load, etc.) Which means you then would have to modify a ton of files, because the 'campaign' itself is the main base for this system, so any crons, most of the php scripts, would need to be changed. Whenever I just tell it in the one script that campaignID = broadcastID, attempting to load the script gives a 'invalid column' error because of how the form builder works.

The form builder is a honest mess, over 300KB of coding. I did not actually do it, but they seem to want a 'fix' instantly and it's not a quick job to do if I was to have to do it file per file, so it's the reason why for this one area I simply wanted it to think that campaignID = broadcastID in the link,  without having to mess with a hundred files.


Sorry if I can't explain this well, sometimes have a hard time speaking about it.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Ray Paseur

Yeah, I get it.  That's what I meant by a brittle design - even a modest change like this one will break lots of things.  Suggest you leave the question open for a while; maybe someone in the Apache Zone will pick up on it and give you a rewrite rule that can translate the URL.
Valleriani

ASKER
Yeah I agree, it was rather a pain, and they don't understand the concept that a simple thing like that breaks everything/expect a change fast, bit of a pain. Hopefully someone does have an idea.

Thanks though for the reply!
Valleriani

ASKER
Thank you,

So again, I have a link:

http://test.com/index.php?ulink=campaignArea&page=1

For example, and I want

http://test.com/index.php?ulink=broadcastArea&page=1


to go to the first link. So 'broadcastArea' would get changed to 'campaignArea', using .htaccess rewrite.

Thanks!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ahoffmann

RewriteCond %{REQUEST_URI} !/ulink=campaignArea/
RewriteCond %{REQUEST_URI} /ulink=broadcastArea/
RewriteRule (.*) /index.php?ulink=campaignArea&page=1
Valleriani

ASKER
Apologies, but that looks like it would only work for 'page=1'. needs to be dynamic, aka any sort of variables added after it. can be page10, maybe another & variable. I could get them all if needed, but the variables do change. I believe in the link they have about 4-5 of them.
ASKER CERTIFIED SOLUTION
ahoffmann

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Valleriani

ASKER
Thank you.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck