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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:21:05+00:00 2026-06-13T06:21:05+00:00

First time here, and I’m a bit of a mod_rewrite and regex noob, so

  • 0

First time here, and I’m a bit of a mod_rewrite and regex noob, so please let me know if I’ve missed anything. I’ve searched here and elsewhere all day but not found exactly what I need.

I’m looking for a set of RewriteConds and RewriteRules that will accomplish the following:

  • remove the www, if present in URL
  • redirect into a folder, if not already present in URL
  • preserve the rest of the URL

I have a web app installed in a specific subfolder (we’ll call it /webapp) which is configured to require no www on the url. It presents a stupid annoying message to the user if they include the www. I can dig into the app and reprogram that, but I’d like to handle that for the users through .htaccess and mod_rewrite, and simultaneously dump them into the folder, if they forget to type it, doing all of this with a 301 redirect.

For example, I’d like any of the following requests

http://www.mydomain.org/webapp/anything
http://www.mydomain.org/anything
http://mydomain.org/anything

To be redirected to

http://mydomain.org/webapp/anything

And obviously if a “correct” URL (one starting with http://mydomain.org/webapp/) is requested, it’s not rewritten at all.

My best guess so far is as follows:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.mydomain\.org$ [NC]
RewriteRule ^(.*)$ http://mydomain.org/$1 [R=302]

RewriteCond %{REQUEST_URI} !^/webapp.*$ [NC]
RewriteRule ^(.*)$ http://mydomain.org/webapp/$1 [R=302]

This seemed to work according to http://htaccess.madewithlove.be/ but in practice, not so much.

Thanks in advance.

  • 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-06-13T06:21:07+00:00Added an answer on June 13, 2026 at 6:21 am

    Found the answer myself here: BowlerHat

    Looks like this:

    # First just remove the www
    RewriteCond %{HTTP_HOST} ^www\.mydomain\.org$ [NC]
    RewriteRule ^(.*)$ http://mydomain.org/$1 [L,R=301]
    
    # Now redirect into the folder
    RewriteCond %{REQUEST_URI} !webapp/ [NC]         # if the provided URI does not start with /webapp,
    RewriteRule (.*) http://mydomain.org/webapp/ [L,R=301]         # redirect user to /webapp/ root
    

    I decided that if users try to visit mydomain.org/somethingsomething, just to send them to the root of the webapp, rather than /webapp/somethingsomething.

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

Sidebar

Related Questions

This is my first time on here, so I'm bit nervous and please forgive
this is my first time posting here, but I didn't know where else to
Its my first time here and I don't know how to indent this sorry
first time posting here, Googled for a few hours and I couldn't find anything.
I'm first time poster here trying to pick up some Python skills; please be
first time posting here, but god know's I use this site to search for
my first time here, title is bad i know :) Well, this is what
Hi there , it my first time here - please go easy on me!
This is my first time here and I am a beginner so kindly bear
This is my first time here so I hope I post this question at

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.