Issues arising from URL encoded characters that fail to get rewritten

I have set up rules for dynamic redirects to point old URLs to new locations. However, I encountered an issue where the redirect failed when URL Encoded Characters were present in the URLs. Here is an example of such URLs:

www.example.com/ebc-drama-yebet-sira/yebet-sira-%E1%8B%A8%E1%89%A4%E1%89%B5-%E1%88%B5%E1%88%AB-drama-part-1-video_80c33bc56.html

In order to address this issue, I need a rule to remove characters like: %E1%8B%A8%E1%89%A4%E1%89%B5-%E1%88%B5%E1%88%AB
These characters represent the Amharic word: የቤት-ስራ.
The rule should remove non-alphanumeric characters from URLs while preserving special characters like "-" and "_" along with URL Encoded Characters.
I have tried the following:

RewriteRule ^/?(.*)$ /$1 [L,R=301]

and :

RewriteRule (.*)[^a-zA-Z0-9](.*) $1$2 [N]

Htaccess file:

Options -MultiViews
RewriteEngine On
RewriteRule ^index.html$ index.php
... (rest of the code remains the same)
RedirectMatch 301 ^/[\w-]+/([\w-]+\.html)$ /$1

Thanks.

Answer №1

To enhance your website's performance, you can implement the following rules in your site's main .htaccess file:

RewriteEngine On

# Exclude all css/js/images files from the rewrite rules below
RewriteRule \.(?:jpe?g|gif|bmp|png|ico|tiff|css|js)$ - [L,NC]

RewriteCond %{REQUEST_URI} !^/(admin|articles?|user|tags|embed|playlist|uploads)(/.*)?$ [NC]
RewriteRule ^(.*)[^\w/.-]+(.*\.html)$ $1$2 [DPI,N,E=SP:1]

RewriteCond %{ENV:SP} =1
RewriteRule ^[\w.-]*$ /$0 [L,R=302,NE]

# Disable RedirectMatch 301 rule

# Additional RewriteRules go here

By applying these rules, a URL like

/ebc-drama-yebet-sira/yebet-sira-%E1%8B%A8%E1%89%A4%E1%89%B5-%E1%88%B5%E1%88%AB-drama-part-1-video_80c33bc56.html
will be redirected to
/ebc-drama-yebet-sirayebet-sira---drama-part-1-video_80c33bc56.html
after removing special characters.

Answer №2

Experiment with

[^a-zA-Z0-9-_./]

Feel free to try out your pattern on this platform

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Executing JavaScript function by clicking on <img>

I've been developing a website similar to YouTube, and I'm facing difficulties with the Like/Dislike feature for comments. Currently, I have implemented it in the following way: when a user clicks on an image (thumbsUp.png or thumbsDown.png), a ...

Using ExtJS to populate a panel with data from various sources

I am currently working with an Ext.grid.GridPanel that is connected to a Ext.data.JsonStore for data and Ext.grid.ColumnModel for grid specifications. Out of the 10 columns in my grid, 9 are being populated by the json store without any issues. However, I ...

What may be causing my Ajax call to get stuck at readystate 1 and not progress further

I've double-checked all my code, yet I'm not getting any response from my Ajax call. Can someone help me figure out what's wrong? function fetchPokemonData() { const apiRequest = new XMLHttpRequest(); apiRequest.open('GET', &apo ...

The POST response I received was garbled and corrupted

Operating under the name DownloadZipFile, my service compiles data and constructs a Zip file for easy downloading. This particular service provides a response that contains the stream leading to the file. A Glimpse of the Service: [HttpPost] public Actio ...

Easily refresh multiple select options by using the ajax updater function in prototype

After carefully reviewing the documentation for Ajax.Updater(), I noticed that the first argument to the constructor should be container (String | Element) – The DOM element whose contents will be updated as a result of the Ajax request. This can eith ...

Utilize data obtained from an ajax request located in a separate file, then apply it within a local function

Seeking assistance in navigating me towards the right path or identifying my errors. Pardon if my explanation is unclear, please be gentle! Currently, I am engaged in developing a function that executes an ajax call with a dynamically generated URL. The o ...

The JQuery function fails to execute following a successful Ajax request

I recently ran into an issue with my Ajax call. Here's the code snippet in question: $("#start-upload-btn").click(function(){ $.ajax({ type: "post", url: "", data: { newProjectName: $('#project-name') ...

Melodic Streaming Platform

I currently have a client-side application built using React. I have a collection of music stored on my Google Drive that I would like to stream online continuously. I lack experience in server-side programming. Can you suggest any resources or steps I s ...

The body onload function fails to run upon the page loading

I'm having trouble with my body onload function not executing. When I load the page, I want to display all records that are selected in the drop_1 dropdown and equal to ALL. I have a script that sends values q and p to getuser.php. The values sent are ...

Is it possible to click the back button on your browser and return to an ajax page while keeping it in the same appearance?

I've been researching different jquery history plugins, but I haven't come across any examples that fit my specific situation. This is leading me to believe that what I'm trying to accomplish may not be feasible. Our search page is highly c ...

Massive Memory Drain Due to XMLHttp POST Request

Is there a way to prevent XHR POST Memory leak in my web app? I have searched extensively for solutions but have not found any satisfactory answers. My issue is similar to the one described in this blog post that outlines the problem without offering any f ...

The code functions perfectly on my local machine, however it is not cooperating on the HostGator server

A selection box based on values should appear in text fields, The current code is functional in local host but not working on the hostgator server For example, displaying country options based on the selected state and districts based on the selected sta ...

Fluctuating updated site (ajax)

What method do you recommend for maintaining the data in a table on a page current? Currently, I am using a timer that connects to the server via ajax every 2 seconds to check for updates. Is there a way to trigger an event or function only when the cont ...

Unraveling JSON data retrieved from a MySQL query

After successfully encoding a MySQL result from PHP into JSON, I am now faced with the task of decoding it using JavaScript. Let's assume that my string returned is: [{"0":"x","1":"z"},{"0":"xs","1":"zz"}] I would appreciate some guidance on how to ...

Issues with sending an AJAX POST request to a PHP script

Hello, I am trying to send a variable from an AJAX JavaScript file to a PHP file. Here is what I have done so far: var request = createRequest(); var deletenode = node.id; window.alert("nodeid=" + deletenode); var vars = "deletenode ...

Automatically tapping the Quora "expand" button through code

I am attempting to automate the clicking of the "more" button located at the bottom of a page like using watir. Below is the code I currently have: require 'watir-webdriver' b = Watir::Browser.new b.goto 'quora.com/'+ ARGV[2] + ' ...

What steps can I take to identify and manage a browser's inability to play a media file?

I am currently utilizing a JavaScript utility to stream mp3 content. Unfortunately, there are instances where I direct users to a file that cannot be played due to external factors. In such cases, Firebug displays an error message indicating that the file ...

Combining Extjs combo with autocomplete functionality for a search box, enhancing synchronization capabilities

When using autocomplete search, I've encountered an issue. If I type something and then make a mistake by deleting the last character, two requests are sent out. Sometimes, the results of the second request come back first, populating the store with t ...

Having difficulty sending variables to onreadystatechange

Here is the latest version of the source code: var xhttp = new XMLHttpRequest(); function passVars(var1, var2, var3) { if (var1.readyState == 4) { if (var1.status == 200) { var data = var1.responseText; if (data) { playSuccess ...

Error message "Unexpected token" occurs when attempting to use JSON.parse on an array generated in PHP

My attempt to AJAX a JSON array is hitting a snag - when I utilize JSON.parse, an error pops up: Uncaught SyntaxError: Unexpected token Take a look at my PHP snippet: $infoJson = array('info' => array()); while($row = mysqli_fetch_array($que ...