SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Aug 2005
    Location
    Lithuania, Europe
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mod_rewrite and PHP

    Can mod_rewrite only be used if you have the rights to restart Apache? If so, does that mean that the absolute majority of shared hosts (by shared I don't include VPS) do not allow mod_rewrite?

    In the case mod_rewrite is not available on shared hosts, which way would you recommend to use to make links SEO friendly with PHP only?

  2. #2
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    United Kingdom
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think mod_rewrite rules can be put in .htaccess files. Enabling mod_rewrite would probably require a restart though.

    Would you consider a URL of the form
    Code:
    http://www.myhost.com/index.php/some/params/
    search engine friendly? if so then just use the PATH_INFO array. If you want to avoid having index.php in the URL then mod_rewrite is the only option on Apache I think.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2005
    Location
    Lithuania, Europe
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I guess
    HTML Code:
    http://www.myhost.com/index.php/some/params/
    is not considered a search engine friendly URL.

    Do most shared hosts allow using mod_rewrite via .htaccess?

  4. #4
    Obey the Purebreed trib4lmaniac's Avatar
    Join Date
    Dec 2004
    Location
    Cornwall, UK
    Posts
    594
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ReeD
    Do most shared hosts allow using mod_rewrite via .htaccess?
    I believe so. Try creating a .htaccess file on your server with something like:
    Code:
    RewriteEngine On
    RewriteRule ^/(.+)$ /index.php?url=$1
    Or something like that.

  5. #5
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most web hosts have already created a .htaccess file for you anyway, is the impression I have, so Apache is already set up for you in regards to the manner in which you can use .htaccess.

    Not come across one that hasn't yet.

  6. #6
    SitePoint Addict
    Join Date
    Aug 2005
    Location
    Lithuania, Europe
    Posts
    295
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's good news for me

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    ReeD,

    Dr Livingston is quite correct - as far as I know. Some hosts do allow you to use/modify .htaccess and some don't. ASK any host you're thinking of using and they should tell you straight out.

    Enabling mod_rewrite, like Shrike said, is a two part question. I've covered the enable and test in my signature article but, if it's not already enabled, Apache must be restarted (to have the changes to httpd.conf read by Apache).

    As for trib's code, PLEASE learn a bit of regex before attempting to use mod_rewrite as you'll cause yourself more problems than not by using wildcards. (Here I go again ranting about the EVERYTHING module! ) Once again, my article was ONLY written to prevent my repeating everything in each thread - the tutorial on creating specific mod_rewrite code should also be helpful.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •