Click here to Skip to main content
15,936,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I'm trying to rewrite URLs such as
to get rid of the unnecessary slashes in both the filename and query string.

There's a file called index.php within the document root which takes the GET parameter __method to know which method the user is calling - in this case, 'alert'.

Here's my .htaccess file:

RewriteEngine On

RewriteBase /

# Test:

# Remove slashes in query string
RewriteCond %{QUERY_STRING} (.*)/(.*)
RewriteRule ^(.*)$ %{REQUEST_URI}?%1%2 [R=307,L]

# Remove double slashes from URL
RewriteCond %{THE_REQUEST} //
RewriteRule ^.*$ $0 [R=307,L]

# Remove 'index.php'
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=307,L]

# Put slash after filename; /alert?a=b -> /alert/?a=b
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$ /$1$2/ [R=307,L]

# Add __method parameter
RewriteRule ^(.*)$ index.php?__method=$1 [NC,QSA]

The problem is that it's rewriting to
...but should be rewriting to

...with '__method=alert' passed in the background. This works fine if 'RewriteRule ^(.*)$ %{REQUEST_URI}?%1%2 [R=307,L]' is commented out.

This seems to be happening because it's interfering with the query string, but I have no idea how to approach fixing it.

I'd really appreciate any help you can give with this. You can test what __method is being interpreted as by going to<anything>/?debug=true
and looking at 'debug-method'.

What I have tried:

Visiting many websites, which don't work for my specific situation
Updated 6-Feb-19 5:56am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900