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 1002731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:52:15+00:00 2026-05-16T07:52:15+00:00

Any request to www.example.com/* must be redirected to www.example.com/blog/* If no www. prefix, add

  • 0

Any request to www.example.com/* must be redirected to www.example.com/blog/*

If no www. prefix, add it.

Importantly, if there exists any directory matching the request URI, don’t redirect.

Example:

(www.)example.com/<request> -> www.example.com/blog/<request> except <request> === <dirname>

Following the above 3 conditions, how do I code a .htaccess? Please help!
Thx 😉

  • 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-16T07:52:16+00:00Added an answer on May 16, 2026 at 7:52 am

    This should do what you wanted. I also added in a “don’t redirect if this file exists”, since I wasn’t sure what was in your existing directories. You can try removing it by taking out the second RewriteCond if you don’t want it, but I think it’s probably necessary to some extent.

    RewriteEngine On
    
    # Check if the requested path is not a real file or a
    # real directory
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    # If the current request doesn't start with "blog", and
    # it's not a real file or directory based on the above
    # conditions, add "blog" to the front of the request, and
    # mark an environment variable that indicates we'll need
    # to redirect
    RewriteRule !^blog blog%{REQUEST_URI} [E=CHANGED:TRUE]
    
    # Check if the host doesn't start with "www.", or if we've
    # marked the change variable above, since in either of those
    # cases we need to perform a redirection (We do it this way,
    # since we'll at most send one redirect back to the client,
    # instead of the potential two we might send if we didn't
    # combine the checks)
    RewriteCond %{HTTP_HOST}  !^www\. [OR]
    RewriteCond %{ENV:CHANGED} =TRUE
    # Capture the non-"www." part of the host, regardless of
    # whether or not the "www." is there
    RewriteCond %{HTTP_HOST}   ^(www\.)?(.*)$
    # Redirect anything to the corrected URL, using the
    # backreference from the above condition, and the entirety of
    # the requested path (possibly modified by the above RewriteRule)
    RewriteRule ^.*$   http://www.%2/$0 [R=301,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want any request to http://example.com/ * to be redirected to http://www.example.com/ *. Where
So... I have a URL like www.example.com/stream/ I need to make any request to
I want to hide any request on the following php file to www.example.com/. www.example.com/index.php
I am registering a request stub as follows: url = http://www.example.com/1 stub_request(:get, url). with(body:
I wanted to rewrite any request with www.example.org, https://www.example.org and http://example.org to https://example.org Is
So, I have at site where I want pages such as; www.example.com/shop/index.php (or any
What's the easiest way to convert these requests: http://www.example.com/en/ http://www.example.com/en/index.php To: http://www.example.com/index.php?language_id=en There's various
There is a website that I visit often... let's call it www.example.com. And, I
I'm try to redirect any request to mydomain.com/video/(.*) to video.mydomain.com/$1. I have the following
Is there any way to easily make a HTTP request with C++? Specifically, I

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.