Mod rewrite: profile.php?id=1 to profile/1

Posted on 2008-11-10
Last Modified: 2012-05-05
I want profile.php?id=1 to look like profile/1. Also, I wonder how I can get the id into a php-variable, as there will no longer be anything in $_GET.

What is the best solution?
Question by:husker475
    LVL 27

    Accepted Solution

    First, change your html code into href="profile/1" (mod_rewrite cannot change html source code).
    Use a rewriteRule in a .htaccess file to rewrite a request of profile/1 back to profile.php?id=1 (internal rewrite):
    RewriteEngine on
    RewriteRule ^profile/([0-9]+)/?$ /profile.php?id=$1 [L]

    Open in new window

    LVL 4

    Author Closing Comment

    Perfect, thank you so much.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
    Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now