Question:

Can mod-rewrite take a messy url and make it display clean in the browser address bar?

by  |  earlier

0 LIKES UnLike

I've seen examples of giving a webpage a clean url and mod re-write will make it the messy version behind the scenes so it works with your organization, but I have the opposite problem. I have a webpage that all the links in it are starting messy, but I don't want the user to see the messy urls in their address bar when they click on a link. So, for example, I have a link that says www.mysite.com/index.php?page=mypage. This is my actual webpage organization. However, I want it so that when the user clicks on this link and then looks up at his address bar after the page loads, it says www.mysite.com/mypage.html. Is this possible?

 Tags:

   Report

2 ANSWERS


  1. Yes, definitely. You'll want something like this (in httpd.conf or .htaccess):

    RewriteEngine On

    RewriteCond %{REQUEST_URI} != ^/index.php

    RewriteRule ^/(.*) /index.php?page=$1

    I haven't tested that, but it should work. The RewriteCond line just checks to make sure they aren't already requesting index.php (so that you won't get a loop); the RewriteRule says to take anything after the first slash in the request (the stuff in the parentheses) and pretend like that appeared after /index.php?page= . (The $1 means "whatever appeared in between the parentheses earlier in the line. You can have more sets of parens, which would map to $2, $3, etc.)

    http://httpd.apache.org/docs/2.2/rewrite... is a good starting point for mod_rewrite information.


  2. this is how you do this

    1) Open a note pad doc.

    2) Insert the below code.

    <META HTTP-EQUIV=Refresh CONTENT="0;URL=http://www.mysite.com">

    3) Repalce the  mysite.com with your target url.

    4) save it as a .html file

    5) upload it to the server.

    This will trigger a "meta refresh", when any body visits your .html page, they will be redirected to your target url.

    google on how to mask url

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.