LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-14-2011, 01:29 PM   #1
Eddie Adams
LQ Newbie
 
Registered: Sep 2007
Posts: 22

Rep: Reputation: 0
htaccess rewriterule regex


anyone can help me with this? i am trying to rewrite the following format:

colors/veveo/7232/

to

veveo/7232/swatch.html

The next rewriterule doesn't:
Code:
RewriteRule colors\/([-_A-Za-z0-9]*)\/([-_A-Za-z0-9]*)\/?$ $1/$2/swatch.html

Last edited by Eddie Adams; 03-14-2011 at 03:01 PM.
 
Old 03-14-2011, 02:47 PM   #2
Eddie Adams
LQ Newbie
 
Registered: Sep 2007
Posts: 22

Original Poster
Rep: Reputation: 0
Also this does not work:

Code:
RewriteRule ^colors/([^/]+)/([^/]+)/? $1/$2/swatch.html

Last edited by Eddie Adams; 03-14-2011 at 03:00 PM.
 
Old 03-14-2011, 02:53 PM   #3
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
Blog Entries: 1

Rep: Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059
Hi,


Try this one:
Code:
Rewriterule ^colors/(.*)/([0-9]+)/$ /$2/$1/swatch.html
Cheers
 
Old 03-14-2011, 02:57 PM   #4
Eddie Adams
LQ Newbie
 
Registered: Sep 2007
Posts: 22

Original Poster
Rep: Reputation: 0
Does not work either.

Both the segments can be whatever character, so i tried this...

Code:
Rewriterule ^colors/([^/]+)/([^/]+)/?$ /$2/$1/swatch.html
which doesn't work either

Last edited by Eddie Adams; 03-14-2011 at 03:01 PM.
 
Old 03-14-2011, 03:13 PM   #5
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
Blog Entries: 1

Rep: Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059
Are you sure? It's working here.
Clear you browser cache and try again.
 
Old 03-14-2011, 03:29 PM   #6
Eddie Adams
LQ Newbie
 
Registered: Sep 2007
Posts: 22

Original Poster
Rep: Reputation: 0
I was assuming the url was passed reformatted to php. It is not. I picked up the url in php and reformatted it. Now it is working. Any change to do the redirect in htaccess?
 
Old 03-14-2011, 05:29 PM   #7
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,204
Blog Entries: 1

Rep: Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059Reputation: 2059
You mean you want to pass the rewritten URI in a php script?
Then add the [R] flag at the RewriteRule:
Code:
Rewriterule ^colors/([^/]+)/([^/]+)/?$ /$2/$1/swatch.html [R]
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl to find regex and print following 5 lines after regex casperdaghost Linux - Newbie 3 08-29-2010 08:08 PM
.htaccess RewriteRule map URL to another nuttynibbles Linux - General 1 04-19-2010 02:36 AM
[SOLVED] Apache .htaccess redirection '?' (question mark character) using regex angel115 Linux - Software 2 11-05-2009 03:37 AM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 05:10 AM
Help w/ Apache htaccess (RewriteRule) bhuwan Programming 1 03-16-2006 06:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration