Redirect url contains both numbers and letters with Htaccess

 To redirect a URL that contains both numbers and letters using .htaccess, you can use the following code in your .htaccess file:


bash

Copy code

RewriteEngine on

RewriteRule ^([0-9]+)/([a-zA-Z]+)/?$ /newpage.php?id=$1&title=$2 [NC,L]

This code uses the RewriteEngine directive to turn on the URL rewriting engine in Apache, and the RewriteRule directive to define a new URL rewriting rule. The rule uses a regular expression to match URLs that contain one or more numbers, followed by a forward slash, followed by one or more letters. The matched parts of the URL are captured and passed as query parameters id and title to the newpage.php script.


The [NC,L] flags at the end of the RewriteRule directive indicate that the rule is case-insensitive (NC) and that it should be the last rule processed (L).


You can test this code by accessing a URL like http://example.com/123/abc in your browser. If the .htaccess file is set up correctly, the URL should be redirected to http://example.com/newpage.php?id=123&title=abc.

Post a Comment

Previous Post Next Post