Author Topic: mod_rewrite  (Read 2870 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
mod_rewrite
« on: March 03, 2010, 11:04:50 PM »
Something is messed up with my mod_rewrite because it isn't working.  I enter:

http://www.test.com/v2/models/si/1

And it's supposed to rewrite to this:

http://www.test.com/v2/index.php?req=prod&cat=si&model=1

Here's my htaccess file:

Code: [Select]
RewriteEngine on

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName test.com

ErrorDocument 404 /404.php
RewriteRule ^/models/([a-z]+)/([0-9]+)$ index.php?req=prod&cat=$1&model=$2 [NC,L]
RewriteCond %{HTTP_HOST} ^blah.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.blah2.com$
RewriteRule ^(.*)$ "http\:\/\/www\.test\.com" [R=301,L]

Right now it just goes to a blank page.  HELP!?    :wall:

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: mod_rewrite
« Reply #1 on: March 04, 2010, 01:21:37 AM »
Turn on the mod_rewrite log (RewriteLog) and see what it is doing.

Off the top of my head though:
Code: [Select]
RewriteRule ^/models/([a-z]+)/([0-9]+)$ index.php?req=prod&cat=$1&model=$2 [NC,L]That might need to be
Code: [Select]
RewriteRule ^/v2/models/([a-z]+)/([0-9]+)$ v2/index.php?req=prod&cat=$1&model=$2 [NC,L]

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: mod_rewrite
« Reply #2 on: March 04, 2010, 03:07:55 PM »
rewriteLog throws an internal server error as soon as I put it in the .htaccess file.

Here is my structure:

public_html
  /site -> production site
  /v2 -> testing site

What if I move the .htaccess file down into the site and v2 levels?  Right now I have it at the public_html level.

Because I did what you suggested with the change to the rewrite condition and it did it but the CSS/JS files didn't work because they're relatively addressed... it's like it ignored the v2 stuff.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: mod_rewrite
« Reply #3 on: March 04, 2010, 03:34:35 PM »
Ok, I have this:
Code: [Select]
RewriteRule ^models/([a-z]+)/([0-9]+)$ v2/index.php?req=prod&cat=$1&model=$2 [NC,L]at the v2 level and it's loading the page but it's not grabbing the correct paths for the CSS/JS files so none of my images/styling/JS works.  What gives?

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: mod_rewrite
« Reply #4 on: March 04, 2010, 04:40:31 PM »
After some further googling... looks like I'm going to be creating a bunch of absolute paths to shit.  That sucks.

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: mod_rewrite
« Reply #5 on: March 04, 2010, 06:46:55 PM »
Reverse proxy?
This signature intentionally left blank.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: mod_rewrite
« Reply #6 on: March 05, 2010, 12:48:34 PM »
Can you be more specific?  I did a little googling but I'm not clear on how that would help me.

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: mod_rewrite
« Reply #7 on: March 05, 2010, 01:41:53 PM »
Where in the tree under /v2/ are the JS and CSS files?

I don't remember the exact syntax but I think the rewritecond has like a -f and -d option that checks to see if the file or directory does or doesn't exist.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: mod_rewrite
« Reply #8 on: March 05, 2010, 03:02:08 PM »
/v2/style for all style sheets
/v2/libs for all JS files

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Re: mod_rewrite
« Reply #9 on: March 05, 2010, 03:50:00 PM »
A reverse proxy would send all traffic to a given path to another server internally (or externally). It's probably overkill if you can get the correct rewrite rules but I've come to wonder how I lived without them in my development world. All of your relative paths would then work based off the base url since they're actually getting served under that context.
domain.com/site/
domain.com/v2/

You can also do stuff like put one reverse proxy in front of all developer machines and use named virtual hosts to pass through to internal dev machines and not have to open lots of alternate ports on the firewall.

Again, overkill for your problem probably, but they're super cool. Not to mention pretty much required for high availability/load balancing.
« Last Edit: March 05, 2010, 03:56:21 PM by tgm »
This signature intentionally left blank.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: mod_rewrite
« Reply #10 on: March 08, 2010, 10:14:39 PM »
Well, I'm working with a client on a shared hosting account with like 500 unique visitors per month... we're not talking a massive site.  So it doesn't even sound like I can do it in this case.