1

i want to page redirection and unable to write condition for it

have different scenario want to redirect friendly url to query string base

http://www.domainname.com/directoryname/friendly-url-goes-here_123456.html

friendly-url-goes-here can be like this friendly_url-goes_23-here_123456.html, i just want 123456

and page get redirected to this

http://www.domainname.com/detail-page?id=123456

123456 will be a variable

2
  • what language are you using? Commented Aug 28, 2014 at 21:25
  • want to do it using .htaccess, using PHP ( wordpress ) Commented Aug 28, 2014 at 21:26

2 Answers 2

4

You can use this lookahead based regex:

\d+(?=\D*$)

RegEx Demo

.htaccess:

Inside your root .htaccess you can use this rewrite rule:

RewriteEngine On

RewriteRule ^directoryname/.*?(\d+)\D*$ /detail-page?id=$1 [L,QSA,NC,R]

Reference: Apache mod_rewrite Introduction

Apache mod_rewrite Technical Details

Apache mod_rewrite In-Depth Details

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

6 Comments

Thanks for the rewrite but its not redirecting
It is a silent rewrite. If you want redirect then add R flag to make it [L,QSA,NC,R]. Also do you .htaccess in directoryname also?
.htaccess is on root domain.com
using basic wordpress rewrite rules from here codex.wordpress.org/htaccess
Thanks a lot @Anubhava, can you please guide me where form i can learn all these pattern stuff
|
0

May be this could be one way to do it:

(\d+).html$
  • \d+ match a digit [0-9]

Online Demo 1

and this is another way:

\d+(?=\.html$)
  • (?=.html$) It is a positive lookahead - it assert that the regex below can be matched if it contains at end($) a .html

Online Demo 2

Comments

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.