How to redirect a url with a percentage (%) symbol?

Member

by gilbert , in category: Third Party Scripts , 23 days ago

How to redirect a url with a percentage (%) symbol?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lottie , 22 days ago

@gilbert 

You can redirect a URL with a percentage (%) symbol by encoding the URL before setting up the redirection. Here's how you can do it using a few different methods:

  1. Using PHP:
1
2
3
4
5
<?php
$url = 'http://www.example.com/page%20with%20percentage%20symbol';
$encoded_url = urlencode($url);
header("Location: $encoded_url");
?>


  1. Using JavaScript:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<!DOCTYPE html>
<html>
<head>
<script>
var url = 'http://www.example.com/page%20with%20percentage%20symbol';
var encodedUrl = encodeURIComponent(url);
window.location.href = encodedUrl;
</script>
</head>
<body>
</body>
</html>


  1. Using .htaccess file (Apache server):


Create or edit the .htaccess file in the root directory of your website and add the following line:

1
Redirect /page%20with%20percentage%20symbol http://www.example.com/new-page


Replace /page%20with%20percentage%20symbol with the encoded URL path and http://www.example.com/new-page with the new URL you want to redirect to.


After performing one of these methods, the URL with the percentage (%) symbol should now redirect to the new URL successfully.