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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:12:12+00:00 2026-05-27T18:12:12+00:00

I have a small htaccess file, which contains some simple rules. First I want

  • 0

I have a small htaccess file, which contains some simple rules.
First I want to redirect or to add www at the begin of the main domain:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|serv)\.(.*\-.*)\.com [NC]
RewriteRule ^(.*) http://www.maindomain.com%{REQUEST_URI} [L,R=301]

In the second step I want to remove the folder serv from the URI.
I have following folder structure:

http://www.maindomain.com

  • serv/
  • content of the main web page

To do that I have following rules:

RewriteCond %{HTTP_HOST} ^serv.* [NC]
RewriteCond %{REQUEST_URI} !^/serv.* [NC]
RewriteRule ^(.*) /serv/$1 [L,QSA]

This works so far, but my own rewrite rules conflicts with the conditions and rules above:

RewriteEngine On
RewriteBase /
RewriteRule ^search/$ search.php [L,QSA]

So my URI get sometimes something like that http://www.maindomain.de/search/search.

Here is my full htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www|serv)\.(.*\-.*)\.com [NC]
RewriteRule ^(.*) http://www.maindomain.com%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^serv.* [NC]
RewriteCond %{REQUEST_URI} !^/serv.* [NC]
RewriteRule ^(.*) /serv/$1 [L,QSA]

RewriteEngine On
RewriteBase /
RewriteRule ^search/$ search.php [L,QSA]

What is wrong? I don’t find the mistake.

Furthermore I want to know if it is possible, if the subdomain isn’t serv and the URI doesn’t contain serv that the subdomain will be redirected to www.

  • 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-27T18:12:13+00:00Added an answer on May 27, 2026 at 6:12 pm

    if it is possible, if the subdomain isn’t serv and the URI doesn’t contain serv that the subdomain will be redirected to www

    For the last part of your question, add the following to your .htaccess file

    #if the subdomain is not serv
    RewriteCond %{HTTP_HOST} !^serv\.[^\.]+\.de$ [NC]
    #and the uri does not contain serv
    RewriteCond %{REQUEST_URI} !^.*serv.*$ [NC]
    #redirect to www
    RewriteRule .* http://www.maindomain.de%{REQUEST_URI} [NC,L,R=301]
    

    Edit:
    I replaced %1 reference with the host Above, which you can change to match your actual host.

    For the first part of your question, your rule below will match any host that does not begin with www. or serv. that does not have a dash in the domain i.e. it will match www.maindomain.com because it does not have a ‘-`.

    RewriteCond %{HTTP_HOST} !^(www|serv)\.(.*\-.*)\.com [NC]
    

    This will result in an infinite redirect as you observed.

    To fix it change it to the following

    #if host is NOT www.anything.com or serv.anything.com
    RewriteCond %{HTTP_HOST} !^(www|serv)\.[^\.]+\.com$ [NC]
    #redirect to www.maindomain.com
    RewriteRule .* http://www.maindomain.com%{REQUEST_URI} [L,R=301]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small issue with some .htaccess rules on our website - http://www.presencemultimedia.co.uk
I have small utility that does some processing on a file and changes the
First of all, I have following directory structure: /project_directory/rewriting_experimentation_directory htaccess File realfile.txt What I
I have a .htaccess as follows and some rules are conflicting - I need
If have some rules in my .htaccess: RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l
I have small page which has label, DropDownList and a submit button. <div> <asp:label
I have small problem with my .net 2.0 winforms application. I want to embed
I have small page, it looks follows: Some header Label with text only for
I wrote a small app with Sinatra and have some admin routes (/admin/new, admin/edit/2,
Have small web page at www.peterbio.com/mom/test.htm Someone wrote the code with mouse over and

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.