We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,956 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Regular Expression for URL Rewriting

Hello Guyz,

I could not found any Forum for Web Servers or something related to my problem so I am posting it here.

So I am having trouble with Regular Expressions in HTACCESS.

So what I have in my website is :
ROOT : (my web root is in a sub folder 'sites')
/sites/index.php and other files
/sites/sites/sample_folder_name/index.php and other files

Now what I would like to do is to ReWrite URL :
/sites/sites/sample_folder_name/file_name.php
to :
/sites/file_name.php?siteredirect=sample_folder_name

Remember :
If the URL contains any Request Parameters, then those must also be rewrited, i.e :
Example :
/sites/sites/sample_folder_name/file_name.php?cat_id=1&user=2
to :
/sites/file_name.php?cat_id=1&user=2&siteredirect=sample_folder_name

Currently, the rewrite is working great but I am not able to make them work with parameters.

What I have in my HTACCESS right now :

RewriteRule ^sites\/([0-9A-Za-z_]+)\/([0-9A-Za-z_]+)\.php(.*)$ $2.php(?(?=$3)$3&)siteredirect=$1 [L]
RewriteRule ^sites\/([0-9A-Za-z_]+)\/$ index.php?siteredirect=$1 [L]

Can anyone make it to work with parameters ? Please help !

Thank You

Regards,
Ankur Thakur

2
Contributors
1
Reply
29 Minutes
Discussion Span
1 Year Ago
Last Updated
2
Views
AnkurThakur
Newbie Poster
10 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Use [QSA]

pritaeas
Posting Prodigy
Moderator
9,275 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,457
Skill Endorsements: 86

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0523 seconds using 2.63MB