MOD Rewrite

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

Ok so I'm having a bit of difficulty with my mod rewrite. The project I'm doing this on is a contest program which would allow for many different contest to take place at once.

Example of the raw url (contest is a folder)
http://subdomain.example.com/contest/in ... t=newtest/

I ideally want to goto (contest is a folder)
http://subdomain.example.com/contest/newtest/

So far the best id can get to work is (1st contest is a folder)
http://subdomain.example.com/contest/contest/newtest/

Every time I try to eliminate the variable name contest it kicks me to my page not found page which I must say is most annoying. The htaccess file is located in the the folder

Now the solution I've thought of is to rename the folder to eliminate the double contest but the shorter the link the better.
even if i could get something like this to work as well
http://subdomain.example.com/contest/in ... wtest2013/

I ideally want to goto (contest is a folder)
http://subdomain.example.com/contest/newtest/2013/

I will try adding the rewrite to the htaccess file on the root of the subdomain but it has got to be flawless when i do since there are several folders all with different programs running live
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

OK? So i was able to figure it out by trying to split the year off the variable value strange thing is though i used that code before and it didn't work but now it does

maybe i missed something small I don't know but here is the solution
Code: [ Select ]
RewriteEngine On
RewriteRule ^([A-Za-z0-9]+)/?$ index.php?contest=$1
  1. RewriteEngine On
  2. RewriteRule ^([A-Za-z0-9]+)/?$ index.php?contest=$1
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

A few questions for you.

First the way you have everything written, do you feel it should work? Just not working correctly? Or do you just not know how to write the rule you are needing?

Second question, are you sure your rules from your .htaccess file in your root folder are not colliding or messing things up in the actual folder? Remember that when in a folder it still looks at the root .htaccess as well as the .htaccess in the folder itself.

Finally, if you are just trying to figure out why its not doing what it should, do you have root access to your server, or are you just on some sort of virtual account? Main reason I ask there is you could enable the rewrite log which would show you exactly how things are being processed.

Your index.php script, is that residing in the contest folder at the moment? Trying to follow along here, but confused what .htaccess files you have exactly, and what rules you are using, and not sure entirely the location of your script (folder or root).
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

the first way i wrote it was very straight forward and simple and is should have worked and I wasn't sure if I messed something up or if there was a conflict from the root. I've also done rewrites before but they were all variable/value (http://www.somesite.com/index.php?variable=value == http://www.somesite.com/variable/value) type setups and not just the value so I was going off what I know and trying to make if work for something I've never done before.

I also thought about the root htaccess file over writing my rewrite rules so I commented out the rewrite part in the roots htaccess file and still the rewrite still didn't work even though I looked to me like it should. I even tried to use four different mod rewrite generators to give me a working example I could adapt for my own use but even those didn't work :/

The index file is in the contest folder there is an index file on the root but it is a re director since this subdomain is ment for all the small project/programs that are not deemed worthy for their own subdomain each program is self contained in its own folder.

The way the server is setup I have limited root access. the server is its own box and not a virtual account however but the IT department that run the server have locked down random things which if i bug them enough they give me access too. they also like to hide things to make it hard to find.

All of the servers do a daily backup of all files and I went back to last week when i started messing with this rewrite and believe I've figured out what I did wrong to make it fail

I started out with a rewite like http://www.somesite.com/folder/variable/value
Code: [ Select ]
RewriteEngine On
RewriteRule ^contest/([A-Za-z0-9]+)/?$ index.php?contest=$1
  1. RewriteEngine On
  2. RewriteRule ^contest/([A-Za-z0-9]+)/?$ index.php?contest=$1


I then removed the word contest but not the slash. I'm not sure what I was thinking of the time and why i didn't remove it maybe i forgot it or saw it as a regular expression.
Code: [ Select ]
RewriteEngine On
RewriteRule ^/([A-Za-z0-9]+)/?$ index.php?contest=$1
  1. RewriteEngine On
  2. RewriteRule ^/([A-Za-z0-9]+)/?$ index.php?contest=$1


after getting some breakfast and a coffee I started to play with this idea

http://www.somesite.com/folder/newtest/2013/ == http://www.somesite.com/folder/index.ph ... ewtest2013

Code: [ Select ]
RewriteEngine On
RewriteRule ^([A-Za-z0-9]+)/([0-9]*)/?$ index.php?contest=$1$2
  1. RewriteEngine On
  2. RewriteRule ^([A-Za-z0-9]+)/([0-9]*)/?$ index.php?contest=$1$2


when I was messing with this I got it to work so started to play around with it

and dropped it back to this and it still worked which is what I wanted in the first place.
Code: [ Select ]
RewriteEngine On
RewriteRule ^([A-Za-z0-9]+)/?$ index.php?contest=$1
  1. RewriteEngine On
  2. RewriteRule ^([A-Za-z0-9]+)/?$ index.php?contest=$1


I don't like not knowing what caused the issue and i really don't like not know what fixed it so I looked back and found the issue

Code: [ Select ]
# BAD CODE
RewriteEngine On
RewriteRule ^/([A-Za-z0-9]+)/?$ index.php?contest=$1

# GOOD CODE
RewriteEngine On
RewriteRule ^([A-Za-z0-9]+)/?$ index.php?contest=$1
  1. # BAD CODE
  2. RewriteEngine On
  3. RewriteRule ^/([A-Za-z0-9]+)/?$ index.php?contest=$1
  4. # GOOD CODE
  5. RewriteEngine On
  6. RewriteRule ^([A-Za-z0-9]+)/?$ index.php?contest=$1
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Awesome, so all fixed then?!

What one little forward slash can do to cause hours of pain...
  • ScottG
  • Proficient
  • Proficient
  • ScottG
  • Posts: 477

Post 3+ Months Ago

Yea seems to be all fixed, and yea that one little forward slash or something small and over looked.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 143 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.