+ Reply to Thread
Results 1 to 6 of 6
Like Tree2Likes
  • 1 Post By dongbamage
  • 1 Post By dongbamage

Thread: mod_rewrite (invisible rewrite)

  1. #1
    dongbamage is offline x10Hosting Member dongbamage is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    17

    Question mod_rewrite (invisible rewrite)

    Hi!

    I'm attempting to make my urls prettier by using mod_rewrite.

    So I've setup my .htaccess with the following:
    Code:
    RewriteEngine on
    Rewritebase /
    
    RewriteRule ^articles/([^/]+)/?$ http://myurl.pcriot.com/myfolder/subfolder/index.php?url=$1 [L]
    in the address bar I can then enter:

    http://myurl.pcriot.com/myfolder/sub...icles/contact/

    the redirect works correctly, however the address bar shows:

    http://myurl.pcriot.com/myfolder/sub...p?url=contacts

    How can I make the address bar display my pretty link whilst still rewriting (ie an invisible rewrite)

    I've searched the forums and googled like a madman, but I can't seem to find a solution. Can anybody please help?
    dinomirt96 likes this.

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: mod_rewrite (invisible rewrite)

    Code:
    RewriteEngine on
    Rewritebase /
    
    RewriteRule ^articles/([^/]+)/?$ myfolder/subfolder/index.php?url=$1 [L]
    If you have the http://myurl.com in the RewriteRule, you effectively get a redirect (which will show the new URL) instead of a rewrite (which will show the pretty url)
    Nothing is always absolutely so.

  3. #3
    dongbamage is offline x10Hosting Member dongbamage is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    17

    Re: mod_rewrite (invisible rewrite)

    Thanks so much!

    I had tried with just a relative path but had not included the directory structure and was getting a 404.

    It now works as expected.

    One more question, how can I make it work without 'article' in the url?

    ie http://myurl.pcriot.com/myfolder/subfolder/contact/

    Thanks again!
    karimirt47 likes this.

  4. #4
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: mod_rewrite (invisible rewrite)

    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !=/favicon.ico
      RewriteRule ^(.+)$ myfolder/subfolder/index.php?url=$1 [L]
    If the request does not match a file or directory and is not for the favicon, it sticks it at the end for your index.php to handle. You have to add logic to make sure what to do with the info (ie, if it is a bad request, you serve up a "Resource not located" page).
    Last edited by descalzo; 03-13-2011 at 11:25 AM.
    Nothing is always absolutely so.

  5. #5
    dongbamage is offline x10Hosting Member dongbamage is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    17

    Re: mod_rewrite (invisible rewrite)

    Ok thats fantastic! It works perfectly.

    One last question!

    How can I have the above working for simple urls and another for urls with the format:

    http://myurl.pcriot.com/myfolder/sub...ortfolio&id=78

    Thanks again, I've been bashing my head against this for some time...

  6. #6
    dongbamage is offline x10Hosting Member dongbamage is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    17

    Re: mod_rewrite (invisible rewrite)

    Figured it out:

    RewriteCond %{REQUEST_URI} !portfolio
    RewriteRule ^(.+)$ myfolder/subfolder/index.php?linkdata=$1

    RewriteCond %{REQUEST_URI} portfolio
    RewriteRule ^(portfolio)-([0-9]+)$ myfolder/subfolder/index.php?linkdata=$1&id=$2

    Thanks for helping!

+ Reply to Thread

Similar Threads

  1. The Invisible Man
    By Matt in forum Off Topic
    Replies: 3
    Last Post: 12-13-2008, 05:37 AM
  2. Folder became invisible...
    By iacobos25 in forum Programming Help
    Replies: 2
    Last Post: 11-11-2008, 06:31 AM
  3. Invisible pages
    By Sbiis Saibian in forum Free Hosting
    Replies: 2
    Last Post: 11-05-2007, 07:02 PM
  4. Invisible Gallery
    By digitaljit in forum Free Hosting
    Replies: 2
    Last Post: 06-20-2007, 08:38 AM
  5. Deus Ex: Invisible War
    By DMacK in forum Graphics & Webdesign
    Replies: 4
    Last Post: 03-19-2006, 07:57 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers