Mod_rewrite ???

This is a discussion on "Mod_rewrite ???" within the PHP Forum section. This forum, and the thread "Mod_rewrite ??? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 17th, 2007, 10:12
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Mod_rewrite ???

How the hell do you get mod_rewrite to work? it's just not happening for me.

I tried this:
Code: Select all
RewriteEngine on
RewriteRule ^/([0-9][0-9])/$  /blog.php?article_id=$1
I'm trying to change the URL http://www.theloop.org.uk/blog/blog.php?article_id=30 to http://www.theloop.org.uk/blog/30/ but it's just not happening.

Can anyone tell me what I'm doing wrong? BTW the .htaccess file is in the /blog/ directory
Reply With Quote

  #2 (permalink)  
Old Jul 17th, 2007, 13:18
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Mod_rewrite ???

Code: Select all
RewriteEngine on
RewriteRule ^([0-9]+)$  /$1/ [R]
# redirect users who don't add an end slash to the page with a trailing slash
RewriteRule ^([0-9]+)/$  /blog.php?article_id=$1
# send to ugly URL
By using the + operator, you are catering for all numbers...e.g. 1 or 1000
If you just use ([0-9][0-9]) you are limiting the mod_rewrite to a two digit number.
Have you checked that mod_rewrite is enabled on your server?
Reply With Quote
  #3 (permalink)  
Old Jul 17th, 2007, 13:23
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,620
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Mod_rewrite ???

You've got the hang of mod_rewrite, what you need is to get comfy with regular expressions. here's a good website: http://www.regular-expressions.info/.

As for this...
http://www.theloop.org.uk/blog/blog.php?article_id=30 to http://www.theloop.org.uk/blog/30/
... I think you need this...
RewriteRule ^/blog/([0-9]+)/?$ /blog.php?article_id=$1
...which should take care of...
/blog/3
/blog/30
/blog/3/
/blog/30/
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
  #4 (permalink)  
Old Jul 17th, 2007, 14:48
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: Mod_rewrite ???

They don't seem to work

I tried a few combinations but all I get is page not found.

I know PHP is loading the mod_wrote module as well. I checked in php info.

do you think it's something to do with this? "need to enable mod_rewrite and the FileInfo override in their httpd.conf file"
Reply With Quote
  #5 (permalink)  
Old Jul 17th, 2007, 15:07
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Mod_rewrite ???

Try this in your website's base directory.
Code: Select all
RewriteEngine on
RewriteRule ^blog/([0-9]+)$  /blog/$1/ [R]
# redirect users who don't add an end slash to the page with a trailing slash
RewriteRule ^blog/([0-9]+)/$  /blog/blog.php?article_id=$1
# send to ugly URL
Reply With Quote
  #6 (permalink)  
Old Jul 17th, 2007, 16:04
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: Mod_rewrite ???

Yes! Got it working. Played about with it for a bit and finally got it going.

Thanks a lot guys.

check it out at www.theloop.org.uk/blog

does it work for you too?
Reply With Quote
  #7 (permalink)  
Old Jul 17th, 2007, 16:28
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Mod_rewrite ???

Quote:
does it work for you too?
Yes!
What did you do to get it working?
Reply With Quote
  #8 (permalink)  
Old Jul 17th, 2007, 16:33
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: Mod_rewrite ???

I simplified the rewrite rule to make it work at a really low level. e.g. switching between to .html files.

Then started working up the expression from there.

I added some directory's and stuff and eventually it just worked, I'm using the same rule I had in the first place as well which is really strange.

Just glad it works!
Reply With Quote
Reply

Tags
help, mod_rewrite

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mod_Rewrite Request swiftmed PHP Forum 5 Jun 10th, 2006 06:05
Help with Mod_Rewrite swiftmed Web Page Design 3 Jun 7th, 2006 22:17


All times are GMT. The time now is 01:49.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43