0

I have an input URL that looks something like this:

http://localhost/20north/Numark/product/1/B$@!00$@!4JPPO94$@!

While redirecting this to a new URL, I need to find and remove all occurrences of "$@!" from the last part of the url, so that it becomes:

http://localhost/20north/Numark/product/1/B004JPPO94

Note: The last part can be anything and not just B$@!00$@!4JPPO94$@!. Also, the position of $@! can be anywhere in that last part.

2 Answers 2

3

Using mod_rewrite, you just need this rule:

RewriteRule ^(.*)\$@!(.*)$ $1$2 [N]

Edit:

Actually, there seems to be a problem when the $@! is at the end of the URI. Adding an extra rule to remove the trailing match seems to fix it:

RewriteRule ^(.*)\$@!$ $1
RewriteRule ^(.*)\$@!(.*)$ $1$2 [N]

Not quite sure why that was happening.

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

Comments

1

If you're using php, you could do the following:

<?php 
    $this_url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    if( strpos($this_url, '$@!') !== false ) 
       die(header('Location: ' . str_replace('$@!', '', $this_url))); 
?>

Edit: updated the code to become dynamic

1 Comment

Thanks but we are not using php....apache modules...i am also now adding this to the questions. Thanks anyways

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.