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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:47:12+00:00 2026-06-14T03:47:12+00:00

I have searched some on this site but couldn’t find a right answer to

  • 0

I have searched some on this site but couldn’t find a right answer to my question.

I am trying to force a www redirect and forcing an endslash on each url.

I have the following lines in my htaccess:

# enable rewriting
RewriteEngine on

# if not a file or folder, use index.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L]

# force www
RewriteCond %{HTTP_HOST} !^www
RewriteRule .? http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force endslash
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule (.*) %{REQUEST_URI}/ [L,R=301]

My www redirect is working fine, it will go like:

http://example.com 

to 

http://www.example.com

But now the strange part is, my end slash line is adding the url parameter which I don’t want.

So this will go like:

http://www.example.com/path/without/endlash 

to 

http://www.example.com/index.php/?url=path/without/endslash

Why is it that my defined url parameter is used in this case, and how can I prevent this.

Thanks in advance


EDIT:

thanks to icrew

Only added no-file/no-dir before the endlash entry because otherwise it would redirect my assets.

Final code:

RewriteCond %{HTTP_HOST} !^www
RewriteRule .? http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule (.*) %{REQUEST_URI}/ [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
  • 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-14T03:47:13+00:00Added an answer on June 14, 2026 at 3:47 am

    This part of .htaccess

    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?url=$1 [L]
    

    is responsible for http://www.example.com/index.php/?url=path/without/endslash redirection. So basicly if you do not want url parameter in query string remove those three lines.

    Edit: I figure out what you wanted. Bellow is correct code

    # enable rewriting
    RewriteEngine on
    
    # force www
    RewriteCond %{HTTP_HOST} !^www
    RewriteRule .? http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # force endslash
    RewriteCond %{REQUEST_URI} !(.*)/$
    #next row prevent redirection if final rewriting is done
    RewriteCond %{REQUEST_URI} !=/index.php 
    RewriteRule (.*) %{REQUEST_URI}/ [L,R=301]
    
    # if not a file or folder, use index.php
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    #QSA because I suppose you dont want to discard the existing query string. Remove QSA if you want to discard
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I searched thoroughly this site, but could not find answer to my
I have searched this site extensively but cannot find a solution. Here is the
I have searched for a general solution to this but only find answers to
I have searched (probed ,even) for an answer to this but haven't come up
I have searched on the net and on this site for a solution but
I searched through internet and this site as well but haven't found the answer.
I have searched this topic on google a bit and seen some best practices.
I have searched and searched for this but I think my terminology isn't correct
Okay, so I have searched this site and found many tutorials on how to
I have searched, believe me, I have searched! But I can't find exactly how

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.