Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6072161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:07:46+00:00 2026-05-23T10:07:46+00:00

Let’s say I have the following filesystem setup on my webserver: /www/web/foo/widget.php … /www/app/mvc/controllers/WidgetController.php

  • 0

Let’s say I have the following filesystem setup on my webserver:

/www/web/foo/widget.php
...
/www/app/mvc/controllers/WidgetController.php

I need to figure out how to use mod_rewrite to map page requests (and their respective GET/POST data) for widget.php to its controller WidgetController.php.

It looks like mod_rewrite is super-powerful and thus complex. Is there a quick and easy way for someone to explain to me how to accomplish this? What files do I have to change? Can someone show me a sample rule for this “widget” example?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:07:46+00:00Added an answer on May 23, 2026 at 10:07 am

    Nothing is quick and easy.

    Setup

    First you must make sure that you have the package installed

    To use mod_rewrite, you need to load the extension. Usually, this is done by inmporting the rewrite.so module in the apache2 global configuration (/etc/apache2/apache2.conf)

    Usually all mod_rewrite instruction are written in the virtual host definition. (Say: /etc/apache2/site-available/000default)

    Usage

    First step

    To enable rewrite for one site, you have to ask for it with :

    RewriteEngine On
    

    Then you can begin to write rules. The basic you need to write rules is describe by the following diagram :

    Rewrite States

    (See also : How does url rewrite works?)

    To help me understand how it works, always consider it from the server side (not client side).
    You receive an URL from the client. This URL has a certain format that you had defined. (E.g. http://blog.com/article/myarticle-about-a-certain-topic). But apache can’t understand this by himself, so we need to help him. We know that the controller is page.php and can look up article by name.

    Getting information

    So now we forge a regex to extract information from the URL. All regex are matched against what is following your domain name (here : article/myarticle-about-a-certain-topic without the first / — It can be written though on recent version of rewrite)

    Here we need the article’s name: ^article/(.*)$ will do the job of matching URL against article/<something> and capturing <something> into $1. (For characters meaning, I advise you to look a tutorial on regex. Here ^ is beginning of the string, invisible position after the .com/, and $ the end of the URL)

    So now we need to informe apache that this URL means http://myblog.com/page.php?article=myarticle-about-a-certain-topic

    This is achieved by using a RewriteRule

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

    Restricting to conditions

    To go a bit on advance topics, you may want to apply this rule only if the article name is fetch by GET method. To do this, you can include a RewriteCond like

    RewriteCond %{REQUEST_METHOD} GET
    

    It goes BEFORE a RewriteRule in the file but is tested AFTER it.

    Flags

    If you are making lot of redirection/rewrite, you will have to understand flags

    The most used are [L] and [R]. A little explanation on those :

    • [R] ask for redirection, it can be tuned like [R=302] where 302 is a redirection status number of the HTTP protocol. This will force the client to make a new request with the rewritten URL. Therefore he will see the rewritten URL in his address bar.
    • [L] forces apache to stop treating rules. Be advise that it does mean that the current incoming URL will stop being modified, but the rewritten URL WILL go again through the process of rewriting. Keep this in mind if you want to avoid loops.

    Conclusion

    So you end up with the following block of instructions

    RewriteEngine On
    RewriteCond %{REQUEST_METHOD} GET
    RewriteRule ^article/(.*)$ page.php?article=$1
    

    See also

    You can find additional resources here :

    • A basic tester http://martinmelin.se/rewrite-rule-tester/
    • Cheat sheet : http://www.ranzs.com/?p=43
    • Query_String examples : http://statichtml.com/2010/mod-rewrite-baseon-on-query-string.html
    • Tips : http://www.noupe.com/php/10-mod_rewrite-rules-you-should-know.html and http://www.ranzs.com/?p=35
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let say I have the following desire, to simplify the IConvertible's to allow me
Let's say I have the string: hello world; some random text; foo; How could
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say for example i have URL containing the following percent encoded character :
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I'm building a data access layer for an application. Typically I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.