Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 26th, 2013, 10:01 PM
HDFilmMaker2112 HDFilmMaker2112 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 181 HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 11 h 9 m 44 sec
Reputation Power: 27
Mod_Rewrite for 6 variables

I've got six variables in a url that I need to put into a clean url.

Here's the current .htaccess file:

Code:
RewriteEngine on
Options -MultiViews

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)(/)?$ /index.php?RF=$1&loc=$2&c=$3&ex=$4&jc=$5&f0=$6 [R,QSA]


When I type in what I want to be converted:
darkentity-static.info/DARK/ge/si/14/css/style

It ends up at:
http://darkentity-static.info/index.php?RF=ge&loc=si&c=14&ex=css&jc=style&f0=

when it should be:
http://darkentity-static.info/index.php?RF=DARK&loc=ge&c=si&ex=15&jc=css&f0=style

Can't figure out why, for some reason the regex is not martching the "DARK" in the URL.

Reply With Quote
  #2  
Old February 26th, 2013, 10:18 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,698 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 53 m 2 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Try changing those *s to +s. If the URL it tries to match starts with a slash then your first [^/]* will match nothing (it's optional after all) and the rest of your groups will be pushed down by one.
But you also don't have enough groups: five there when you need six.

In general you should try to be specific with expressions. Is that "14" always a number? Is "css" always a particular thing, like "css" or "js" or "images"? How about that "style"?
Code:
RewriteRule ^/?([^/]+)/([^/]+)/([^/]+)/(\d+)/([^/]+)/([^/]+)/?$ /index.php?RF=$1&loc=$2&c=$3&ex=$4&jc=$5&f0=$6 [L,QSA]

Also:
- It's good practice to anchor the URL at the beginning and end unless you really don't care where in the URL it matches.
- I use ^/? because in some setups the URL may start with a slash and in others it may not. Your setup looks like it does so you could just keep ^/.
- Your [R] flag will redirect the user to the new URL. You sure you actually want that?
- The [L] flag is another good thing to use. Without it, Apache and mod_rewrite will keep on testing, matching, and replacing according to other patterns you might have. [L] tells it to stop.

Reply With Quote
  #3  
Old February 26th, 2013, 10:42 PM
HDFilmMaker2112 HDFilmMaker2112 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 181 HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 11 h 9 m 44 sec
Reputation Power: 27
I was using the R flag for testing purposes, to see where it was trying to go. Will remove on the production version.

Yes, the ex variable (in this case with the value of 14) will always be a digit.

The jc variable (in this case with the value of css) will always either be css or js. I guess, in that instance, I could do "css|js" as the match, instead of "^/".

BTW, that rewrite rule you posted works perfectly, thanks.

I modified it to this:
Code:
^/?([^/]+)/([^/]+)/([^/]+)/(\d+)/([css|js]+)/([^/]+)/?$


Seems to be working, but just thought I double check to make sure that's right.

Last edited by HDFilmMaker2112 : February 26th, 2013 at 11:50 PM.

Reply With Quote
  #4  
Old February 26th, 2013, 11:08 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,698 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 4 h 53 m 2 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Almost. []s are for character sets: any character you put in there will match. Since you put "css|js" with a + it'll match any number of "c", "s", "|" (which loses its special meaning in character sets), and "j" characters. Like "jscjcscjsjcjcss".

Use a simpler
Code:
/(css|js)/

Reply With Quote
  #5  
Old February 26th, 2013, 11:48 PM
HDFilmMaker2112 HDFilmMaker2112 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 181 HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 11 h 9 m 44 sec
Reputation Power: 27
Works excellent. Thanks a ton.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > Mod_Rewrite for 6 variables

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap