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

I'm trying to rewrite URLs such as
https://api.rix-dev.cf//////////alert////?debug=true&/////ds=/////&a=b
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: https://api.rix-dev.cf//////////alert////?debug=true&/////ds=/////&a=b

# 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
https://api.rix-dev.cf/?__method=alert&debug=true&ds=&a=b
...but should be rewriting to
https://api.rix-dev.cf/alert/?debug=true&ds=&a=b

...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
https://api.rix-dev.cf/<anything>/?debug=true
and looking at 'debug-method'.

What I have tried:

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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