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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:09:35+00:00 2026-05-23T06:09:35+00:00

I am having a few problems re-writing flat links using htaccess, I have two

  • 0

I am having a few problems re-writing flat links using htaccess, I have two sets of rules which independently work perfectly well but when put together have an undesirable effect.

The first section adds a trailing forward slash if one is absent and re-writes the url with a 301 divert.

The second converts all of the ‘folders’ into parameters which is then passed to php in a particular format.

We have an unknown number of folders depending on the page so wish to keep the code generic.

The problem is that although the code functionality works (i.e. php is fed the correct parameters) the url is re-written in the wrong format.

Php code:

<?php echo ‘<pre>’;print_r($_GET); echo ‘</pre>’;?>

Sample url: (removed HTTP:// as restricted to two links per question)

localhost/foo/bar 

is re-written to

test.localhost/foo&other[]=bar/ 

with output:

Array
(
    [p] => foo
    [other] => Array
        (
            [0] => bar
        )
)

If you remove the first section for the htaccess then the output is the same and the url remains:

localhost/foo/bar

HTACCESS:

Options +FollowSymlinks
RewriteEngine on

SECTION 1:

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

SECTION 2:

RewriteRule ^(.*)/([^/]+)/?$ $1&other[]=$2 [L]
RewriteRule ^(?!index\.php)([^/]+)/?$ /index.php?p=$1 [L,QSA]
  • 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-23T06:09:35+00:00Added an answer on May 23, 2026 at 6:09 am

    Try these lines instead:

    Options +FollowSymlinks
    # Activate Rewrite Engine
    RewriteEngine on
    # Force trailing slash to be present (only if such file does not exist)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*[^/])$ /$1/ [R=301,QSA]
    # Rewrite rule to real php file (only if such folder does not exist)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/$ /index.php?p=$1&other[]=$2 [NC,QSA,L]
    

    Please note, the last line will only work for URLs of this structure: /foo/bar/. It will not work with /foo/bar (this should never happen as we have special Redirect rule to add trailing slash) as well as with longer URLs like /foo/bar/meow/ — you would need to duplicate and modify last 2 lines.

    Also, if there is a folder that matches URL (e.g. foo/bar/) then rule will not work as well.

    These rules were tested and confirmed to be working. Let me know if you need any modifications.

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

Sidebar

Related Questions

I've been having quite a few problems trying to use Microsoft.SqlServer.Types.SqlGeography . I know
I'm a few days into learning Clojure and are having some teething problems, so
I'm doing maintenance work on an existing Rails site and am having some problems
Having a few problems with output buffering. Mainly, I'm trying to run output buffering
I'm having a few problems trying to position some div s in my website
I am having a few problems loading a table into the designer. I get
I am having a few issues when people are trying to access a MySQL
I'm a rookie designer having a few troubles with this page: http://www.resolvegroup.co.nz/javasurvey.php There are
Having read up on quite a few articles on Artificial Life (A subject I
Having worked with Classic ASP for about 2 years now by creating a few

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.