Go Back   Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum > Services > Web Designing and Development

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-09-2007, 11:05 AM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default Mod Rewrite Tutorial

Just came across this and thought it might be useful to someone. It can be a bit heavy going if you haven't used regular expressions but it's still a good overview of what is possible with mod-rewrite.
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #2 (permalink)  
Old 10-09-2007, 02:40 PM
Dan's Avatar
Dan Dan is online now
Got root?
 
Join Date: Aug 2007
Location: England, UK.
Posts: 756
Default

Yeah, most of my websites use mod re-write now.. infact most websites use them these days anyway. They are the easier way to navigate to a specific location without the need of redirects.
Reply With Quote
  #3 (permalink)  
Old 10-09-2007, 06:25 PM
Senior Member
 
Join Date: Jan 2007
Posts: 948
Default

Gawd Damn it! wish i never read the thread.

I have spend best part of 3 hours trying to mod-rewrite some simple dynamic links. I have tried nearly every example on the net and not one worked. I finally found a vid tutorial that kinda explained it in a language i am used to.

I have just got it to work but i think the problem is i still don't fully understand it.
Now I have simple urls with single query vars attached, as in the id=123 kind. Now it has never bothered me before as i was led to believe that single queries as apposed to complex url queries are fine with search engines...well they are not, and i can prove it.
Anyway, all i want is to remove the ?id='' for something like /var

I finally found this:

Code:
 
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^company/([0-9]+) co_details.php?id=$1
Simple i know but i tried loads without success. Anyhow, this doesn't remove the ?id= and doesn't redirect to the new addy. If i try a 301 redirect it gived a 'page cannot be displayed' error, cos it doesn't exist right!

So, i simply changed the hyperlink to www.aol.com/company/$id
as opposed to www.aol.com/company/find.php?id=$id

Now all works ok but my question is this :is this the right way to do this? Is there an easier way that redirects to a virtual address? does anyone care? Did England really beat the Aussies?
__________________
West Dorset Community
Reply With Quote
  #4 (permalink)  
Old 10-10-2007, 10:40 AM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

I have to confess that as far as mod_rewrite goes then I tend to think working = good and actually understanding why it works is superfluous.

I have a friend who thinks regular expressions are fudgy chocolate moon raisins but personally I avoid them unless absolutely necessary.

And if you were referring to the rugby I refuse to discuss it :p
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #5 (permalink)  
Old 10-10-2007, 01:48 PM
Senior Member
 
Join Date: Jan 2007
Posts: 948
Default

Things could be worse Kev, you could have been a supporter of Welsh Rugby..............................oops! you were....may mistake
__________________
West Dorset Community
Reply With Quote
  #6 (permalink)  
Old 10-10-2007, 02:23 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

...and so it begins *sighs*
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #7 (permalink)  
Old 09-24-2008, 09:17 AM
new member
 
Join Date: Sep 2008
Posts: 2
Default

Hi Guys,

I know this is an old thread, but it concerns exactly what I am trying to do and am really struggling!

It seems initially this was because mod_rewrite was not enabled on my Linux C Panel Premium. I spoke to technical support yesterday and they enabled it, however when I run phpinfo I cannot see it. I queried this with tech support and they said it is definately enabled. I guess I have probably made an error somewhere elese, not being very experienced, so I wondered if there is any other way I could check if mod_rewrite is enabled?

At the moment when I try to access the pages which are supposed to be rewritten (I used a generator to try it out, to ensue it's not an error I have made) give the error 'You don't have permission to access .... Additionally a 404 Not Found error was encountered while trying to use an ErrorDocument to handle this request'

Any ideas guys?

Thanks in advance
Reply With Quote
  #8 (permalink)  
Old 09-25-2008, 10:39 PM
new member
 
Join Date: Sep 2008
Posts: 2
Default

Have got mod_rewrite working now, although having 1000's of URL's it would be great if I could recall field names from the database to use in the URL's rather than having to rewrite each one individually - any ideas. I'm using MySQL and PHP...
Reply With Quote
  #9 (permalink)  
Old 10-07-2008, 01:21 AM
Banned
 
Join Date: Oct 2008
Posts: 5
Default

Cool tutorial!
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:34 PM.
Copyright 2002-2007 WebHosting.uk.com. All rights reserved.
Web Hosting UK Forum