Regular Expression for Mod rewrite via HTACCESS

Question!

I need a regular expression which I can use in an HTACCESS file to rewrite:

http://www.sample.com/dir/1-2-3.php

1 = lower case letters only, no limit on how many

2 = alpha numeric (lower case letters only) and dashes, no limit on how many characters

3 = alpha numeric (upper case letters only), no limit on how many characters

(NOTE: The dashes between 1, 2, 3 are intentional, and will be present in the URL)

to

http://www.sample.com/dir/sub/page.php?v=ABC12345

Where ABC12345 is #3 from the original URL.

By : elbrian87


Answers

If I'm understanding correctly, the following should work.

RewriteEngine On
RewriteRule ^([a-z]*)-([a-z0-9-]*)-([A-Z0-9]*)\.php /$1/$2.php?v=$3 [L]

Hope this helps.



Try this rule in your .htaccess:

Options  FollowSymLinks
RewriteEngine on
RewriteRule ^dir/([a-z]*)-([a-z0-9-]*)-([A-Z0-9]*)\.php$ /dir/sub/page.php?v=$3 [R=301,L,NE,QSA]

R=301 will redirect with https status 301
L will make last rule
NE is for no escaping query string
QSA flag will make sure to append existing query parameter with additional query parameters

$3 is 3rd capture group in your REQUEST_URI
By : anubhava


This video can help you solving your question :)
By: admin