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

  • SEARCH
  • Home
  • 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 6628663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:09:04+00:00 2026-05-25T22:09:04+00:00

Say I have the following site: http://example.com/site that is the same of http://site.example.com I

  • 0

Say I have the following site:

http://example.com/site

that is the same of

http://site.example.com

I was wondering if I could obtain something like this

http://site.example.com/var/

using apache2’s mod_rewrite.


Here’s my try:

RewriteEngine on
RewriteRule ^([^/\.]+)$ /site/?var=$1

this works like a charm when the URL is http://example.com/site, but since I’m just a beginner I don’t know how to get this to work for http://site.example.com.

Any help would be really appreciated.

  • 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-25T22:09:04+00:00Added an answer on May 25, 2026 at 10:09 pm

    The first part redirect example.com/site/var to site.example.com/var.
    Second rewrite rule, rewrite your url in site.example.com,

    RewriteEngine on
    RewriteBase /
    RewriteCond %{HTTP_HOST}%{REQUEST_URI}   ^(www\.)?example.com/site/(.*)
    RewriteRule  (.*)  http://site.example.com/%1  [R=301,L]
    
    RewriteRule ^([^/\.]+)$ /site/?var=$1 [L]
    

    Explanation:
    RewriteEngine on

    this line turns rewrite engine on. otherwise it may fail to work.

    RewriteBase /
    this line sets rewrite base. this directive uses when want to set base URL for per-directory rewrites. default value is current physical path but in most cases, URL-base in NOT directly related to physical filename paths, so it’s wrong to use default. for example when using virtual directory you should set this option correctly to mod_rewrite act well.

    RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^(www.)?example.com/site/(.*)
    in this line first apache joins to variable (host address: www.example.com and request URI : /site/var ). then it checks result with pattern I gave. first of result can be www.
    .after that should be example.com/site/ and at the end it can be anything.

    RewriteRule  (.*)  http://site.example.com/%1  [R=301,L]
    

    this line redirects user request to http://site.example.com/%1 with 301 status code. because it has L flag it’s the last rewrite rule apache checks.%1 is everything marked by (.*) in rewrite condition.

    RewriteRule ^([^/\.]+)$ /site/?var=$1 [L]
    

    this line is the line you put in your question: it rewrites every URL that doesn’t have / and dot with /site/?var=$1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have the following pages: http://www.site.com/folder/page.php?id=89 http://www.site.com/folder/page.php?id=85 http://www.site.com/folder/page.php?id=camel+hump http://www.site.com/folder/page.php?id=76 http://www.site.com/folder/page.php?id=71 http://www.site.com/folder/page.php?id=frog http://www.site.com/folder/page.php?id=62 http://www.site.com/folder/page.php?id=59
Simple quick question.... I have the following link html: <a href=http://www.site.com/ onmouseover= /> I
Lets say I have the following jQuery plugin (this is just an example to
Let's say we have following this: <p class=first>This is paragraph 1.</p> <p class=second>This is
Let's say the domain that is mapped to my root hosting directory is example.com
I have seen this same question in many forms on this site and in
Lets say I have the following mapping: site: { properties: { title: { type:
On my web site I would like to have several sub-domains. Files that create
Let's say I have the following HTML code: <a href=/site/somesite/> somesite</a> My question is
I have this two sharepoint web application that resides on the same server with

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.