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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:33:31+00:00 2026-05-24T22:33:31+00:00

Im trying to implement 2 rules 1) Forced www. I have got it working

  • 0

Im trying to implement 2 rules

1) Forced www.

I have got it working by doing

RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

2) Add trailing forward slash on all urls

I got this far by doing this

RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1/ [R=301,L]

and then I ran into a problem,

type url

1) www.domain.com --rewrites to--> http://www.domain.com/  ---Desired Result

2) domain.com --rewrites to--> http://www.domain.com//  ---Undesired Result

3) domain.com/location1 --rewrites to--> http://www.domain.com/location1/  ---Desired Result

4) www.domain.com/location1 --rewrites to--> http://www.domain.com/location1  ---Undesired Result

How can I write it so that i get these 2 rules working?

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

    this rule will redirect all visits without the www:

    RewriteCond %{HTTP_HOST} ^domain.com
    RewriteRule (.*) http://www.domain.com$1 [R=301]
    

    See that I removed the flag to make it the last rule.

    and the second one to put the trailing slash:

    RewriteRule (.*[^/])$ $1/ [R=301,L]
    

    It won’t redirect when the URL already ends in a slash. You’ll get 2 redirects when someone visits a page without the www and without the slash. If you just want to do this due to search engines, it is fine. If your own site often point to a URL like this, you’ll need another regexp.

    If SEO is your motive, also take a look to canonical URLs

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

Sidebar

Related Questions

I'm trying to implement the following mod_rewrite rule: host.com/developer/ => host.com/developer/index.py host.com/developer/branchX => host.com/developer/index.py?branch=branchX
I've been trying to implement a fluent interface for a set of rules in
I'm working on parse generator for PHP . Currently I'm trying to implement canonical
I am trying to implement some Apache rewrite rules to set the MIME type
I'm trying to implement locale-specific pluralization rules in I18n & Rails, but I'm having
I have a Rails 3 app that I am trying to implement devise and
I have a Rails 3 app that I am trying to implement devise and
Greetings! I'm trying to implement SringSecurity in my project and use Static URL rules.
I am trying to implement a validation strategy in my application. I have an
I'm trying to re-implement ASP.NET MVC routing rules in C++ for my own MVC

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.