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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:56:53+00:00 2026-06-01T13:56:53+00:00

I am having difficulty getting several mod_rewrite rules to work together in my .htaccess

  • 0

I am having difficulty getting several mod_rewrite rules to work together in my .htaccess files. Throughout the enitre site I want to drop the “www.” from all URLs. I am using the following at the document root:

Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301]

Then, in one folder “/help” I want to do 2 rewrites:

  1. change domain.com/help/1 to domain.com/index.php?question=1
  2. change domain.com/help/category/example to domain.com/index.php?category=example

So in domain.com/help I have the following:

Options +FollowSymLinks
RewriteRule ^([0-9]+)/?$ index.php?question=$1 [NC,L]
RewriteRule ^category/([^/\.]+)/?$ index.php?category=$1 [NC,L]

The above 2 .htaccess files work for:
http://www.domain.com to domain.com
domain.com/help/1 to domain.com/index.php?question=1
domain.com/help/category/example to domain.com/index.php?category=example

But, this does not work when I need to combine the 2 rewrites to both drop the “www.” and to rewrite the subfolders to a url variable. e.g.:
http://www.domain.com/help/1 to domain.com/index.php?question=1
gives a 500 error.

Where did I go wrong? And, is this best to do with 2 .htaccess files, or can/should the 2 files be combined into 1 .htaccess file at the document root?

  • 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-01T13:56:55+00:00Added an answer on June 1, 2026 at 1:56 pm

    It looks like what’s happening is the rules in the .htaccess file in the /help folder is getting applied because you’re requesting something in that folder, so the parent folder’s rules won’t get applied. You can have your parent rules passed down if you add a RewriteOptions Inherit in your /help folder’s .htaccess:

    Options +FollowSymLinks
    RewriteOptions Inherit
    RewriteRule ^([0-9]+)/?$ index.php?question=$1 [NC,L]
    RewriteRule ^category/([^/\.]+)/?$ index.php?category=$1 [NC,L]
    

    However, the inherited rules may not be applied in the order that you’re expecting. For example, if you request http://www.domain.com/help/1/ you’ll end up getting redirected to http://domain.com/index.php?question=1 which may not be what you want if you are trying to make SEO friendly URLs by hiding the query string.

    Your best bet may be to move the stuff in the /help folder into the one in your document root so that you can control the order that the rules will be applied:

    Options +FollowSymLinks
    
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301]
    
    RewriteRule ^help/([0-9]+)/?$ /index.php?question=$1 [NC,L]
    RewriteRule ^help/category/([^/\.]+)/?$ /index.php?category=$1 [NC,L]
    

    This ensures the redirect to the non-www domain occurs first, then the /help rules get applied. So when you go to http://www.domain.com/help/1/, you first get redirected to http://domain.com/help/1/ then the help rules get applied and the URI is rewritten to /index.php?question=1.

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

Sidebar

Related Questions

I'm having difficulty getting XQuery to work. I downloaded Saxon-HE 9.2. It seems to
I'm having difficulty getting the Model Binder to work. I thought it was the
I am using NHibernate for an ecommerce site and am having difficulty getting what
I'm having difficulty getting some JavaScript features to work in any other browser besides
I'm having difficulty getting MacVim (7.3-64) to recognize my .vimrc and .gvimrc files since
I'm having difficulty getting the awk command inside a bash script to work. The
I am having difficulty getting this scoring function to work. The objective of my
I'm following a tutorial on php, and am having difficulty getting this to work.
I'm having difficulty getting the GUI layout results I want in an Android app.
I am having difficulty getting the create function of backbone.js to work. My main

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.