SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mod_rewrite and smart URLs?

    Hi all,
    Any help would be much appreciated here!

    I am currently redesigning my site and would like to use mod_rewrite (or another method) to make search engine friendly URL's. I have followed a few tutorials but none seem to work.

    If I have a file called reviews.php, where would be the best place to put it so that I can use the URL:-

    mysite.com/reviews/xbox/18

    With xbox relating to the format of the review, and 18 relating to a DB field.

    Would it be possible to place it at mysite.com/reviews.php so that users can go direct to that also?

    How is this done? Is there one definitive answer?

    Thank you all in advance,

  2. #2
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    >> where would be the best place to put it so that I can use the URL:-
    >> mysite.com/reviews/xbox/18
    The right place is under your document root,
    /reviews.php

    >> How is this done?
    /.htaccess
    Code:
    RewriteEngine On
    RewriteRule ^reviews/([a-z]+)/([0-9]+)/?$ reviews.php?format=$1&id=$2 [NC,L]
    [a-z] means from a-z, upper case can be used because I specified at the end NC (NoCase)
    [0-9] means numeric
    If you need another range of characters let me know,
    with reg exp it's possible.

    >> Would it be possible to place it at mysite.com/reviews.php so that
    >> users can go direct to that also?
    Yes, you can access reviews.php directly (ie /mysite.com/reviews.php )

    Pretty nice, ya ? ;-)


    :-) pippo
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would also be interested in anythign anyone has to say here especially concerning the multiviews method on Windows XP, how do I tell it to use Multiviews does it have to be done elsewhere other than the conf file, specifically a .htaccess?

    There are about three answers to your question spent the last few days trying to research the problem myslef. Do a search here for search engine friendly urls it is very interesting. As I say above I am having a lot of problems with all methods!

    Fake 404 - i.e. folder doesn't exist so redirects toa php 404 and you send it to the right page using if statements.

    MultiViews (I think) Apache looks back through a directory when a folder doesn't exist and will eventually find the file and you can grap the rest of the url using PHP and the explode function.

    mod_rewrite much like above only you have a .htaccess with various regular expressions in it telling it what to do!

  4. #4
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    >> how do I tell it to use Multiviews
    >> does it have to be done elsewhere other than the conf file,
    >> specifically a .htaccess?
    /.htaccess
    Code:
    Options +MultiViews
    Using Options All it is not enabled...I think they do that because it could slow down your server...

    >> Fake 404....
    You are filling error_log for valid URI which is not correct conceptually,
    I don't like it...it's a nice trick but it remains a trick.

    >> MultiViews (I think) Apache looks back through a directory when a
    >> folder doesn't exist and will eventually find the file and you can grap
    >> the rest of the url using PHP and the explode function.
    Personally I don't like MultiViews because it can slow down the server,
    http://httpd.apache.org/docs/content-negotiation.html
    Check MultiViews section @ the above link.

    If I had choice of mod_rewrite I'd use it.


    :-) pippo
    Last edited by pippo; Feb 27, 2003 at 14:27.
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  5. #5
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Pippo, you are a superstar! Thank you so much!

    I'll try it out when I get home from work (boo!)...

    You explained what the "NC" meant at the end of 2nd line, but what does the "L" mean? Is it something to do with symlinks? Or am I completely off the track there?

    Thank you again,

  6. #6
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    >> but what does the "L" mean?
    Left, ie it tells to rewrite parser to stop parsing next rules if they exist when the current rule matchs.
    We had only one rule, but I always prefer to add it...
    It's usefull when you have many rewriterules,
    so when a rule matches it will avoid the parser to check the following rules.

    :-) pippo
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As I ma on I will hijack the topic

    Thanks for the help but it doesn't appear to make any difference, I understand all the advantages and disadvantages I originally figured that Multiviews was the best way to start with (the easiest!).

    This is proving a stupid thought as it has taken ages to configure Apache 2 on XP with PHP and I am not happy

    Anyway basically, my Conf file:

    <Directory />
    Options All MultiViews

    AllowOverride All

    Order allow,deny
    Allow from all

    </Directory>

    Then:

    Options All Multiviews

    Then the .htaccess:
    Options +MultiViews

    <FilesMatch "scri">
    ForceType application/x-httpd-php
    </FilesMatch>

    Alas nothing! the PHP forcetype works a treat as long as you say apache/scri but if you try apache/scri/cheese then nothing, just a directory doesn't exist.

    The reason I am doing this is because I want to eventually run a php script on my hosts server (which I can sort out but I need to know how first!).

    If I can get rewrite to work properly that would also be good so far it doesn't want to know either!

    I need it to do it this one directory only as I am being very specific to which sections of the site have search engine friendly urls this is merely to learn somehting really!

  8. #8
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SiCo,
    first of all...why do you want to use apache 2.* ?
    I'd play with 1.3.27 ( .28 due soon ),
    also I think that your host server have 1.3 installed...so,
    the choice is clear.

    >> Anyway basically, my Conf file:
    >> <Directory />
    >>Options All MultiViews
    >> AllowOverride All
    >> Order allow,deny
    >> Allow from all
    >> </Directory>
    Please modify the directory block that points to your document root.

    Example:
    httpd.conf
    Code:
    DocumentRoot "C:/usr/local/Apache/htdocs"
    <Directory "C:/usr/local/Apache/htdocs">
    	Options All
    	AllowOverride All
    	Order allow,deny
    	Allow from all
    </Directory>
    I didn't use MultiViews there so you have to enable it inside .htaccess as you already did

    .htaccess
    Options +MultiViews

    # Having MultiViews enabled you don't need to have the below lines...
    #<FilesMatch "scri">
    #ForceType application/x-httpd-php
    #</FilesMatch>

    If I have a script /pippo.php
    then launching
    /pippo will call /pippo.php
    /pippo/pluto will call /pippo.php


    :-) pippo
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  9. #9
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for all your help Pippo, it is appreciated greatly!

  10. #10
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will give that a try Pippo thanks the reason I am using 2 is becuase I got it off a magazine cover disc and many people say it is the only one worth using on windows!

    I am willing to change despite the problems I had! And may well do, but the main reason for installing a version of Apache is so I can some how use these rules and the site will work both on and offline (before I had IIS which I believe is another story altogether!).

    No doubt I will get back to you But thank you very much so far.

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok that doesn't do a thing, lets say I drop it and try mod_rewrite

    I will take a look at what you say above but I followed your example from another topic last night and that had no effect, all I have to do (theoretically) (besides installing apache 1.3 ) is to uncomment the mod_rewrite line.

    And tell me Apache 1.3 will make all my tears go away

  12. #12
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Apache 1.3 comes with free Kleenex to mop up those tears, SiCo..

  13. #13
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KMxRetro
    Apache 1.3 comes with free Kleenex to mop up those tears, SiCo..
    Thats what I want to hear! I will download it now

  14. #14
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At last after 4 days of messing luckily not full days Apache 1.3 has solved all my problems, multiviews works, rewrite works, it took 5 seconds to setup, Pippo you are somewhat of a live saver not to give you a too bigger head but thank you very much

    I will probably stick around here as it seems a lot more friendly than the forum I normally use for this sort of thing.

    Now to get it working on my server ho hum . . .

    Thanks

  15. #15
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    UK
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One quick thing I read in one of your topics Pippo about effectively if statmenets int he rewrite, unfortunatley I now can't find this topic to help, what I am after is somehtign to say if the user has a put the variable of the wrong time (numbers not letters) or the user has put a million different variables script/wanted1/wanted2/rubbish/rubbish, bascially a catch all so it won't display a 404.

    Cheers

  16. #16
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SiCo
    One quick thing I read in one of your topics Pippo about effectively if statmenets int he rewrite, unfortunatley I now can't find this topic to help, what I am after is somehtign to say if the user has a put the variable of the wrong time (numbers not letters) or the user has put a million different variables script/wanted1/wanted2/rubbish/rubbish, bascially a catch all so it won't display a 404.

    Cheers
    Sorry I don't understand,
    could you be more clear ?
    Maybe starting a new thread for that ?


    Thanks,
    :-) pippo
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •