Yesh
Yesh

Reputation: 63

GET parameter is fetching undesired file extension

GET is fetching the file extension along with the value. Here is my .htaccess -

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^test/(.*)/(.*)/$ /Test3.php?u=$1&i=$2 [NC,L]
RewriteRule ^test/(.*)/(.*)$ /Test3.php?u=$1&i=$2 [NC,L]
RewriteRule ^test/(.*)/$ /Test3.php?u=$1 [NC,L]

File Test3.php is like this -

<?php
echo $_GET['u'];
echo '<br/>';
echo $_GET['i'];
?>

Url I'm passing - http://example.com/test/something/more/

The output on my browser -

something/more.php

Where as the desired output is

something
more

I have scraped whole of my website to fix this but no luck. Not sure why am I getting that php at the end and the complete value after http://example.com/test/ is going to the first parameter only.

Please help !

Thanks All ! I believe the issue to be coming from this line. Pleas suggest a solution with regard to this.

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*[^.#?\ ]+\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*[^.]+)\.php http://www.example.com/$1 [R=301,L]

Upvotes: 0

Views: 86

Answers (2)

Class
Class

Reputation: 3160

I'm no expert in RewruteRules, but I know some regular expressions and the .* in:

^test/(.*)/(.*)/$

means it matches anything including /'s.

You might want try:

RewriteRule ^test/([^/]+)/([^/]+)/?$ /Test3.php?u=$1&i=$2 [L,NC]
//removed this one because they are basically the same
//by adding '/?' it says that the slash is optional
RewriteRule ^test/([^/]+)/?$ /Test3.php?u=$1 [L,NC]

Someone might want to make a suggestion to the regex, but I think it will work for your purpose.

EDIT: Or you can do something like https://stackoverflow.com/a/14663292/1700963

If anyone has any better example please edit or make a comment.

Upvotes: 3

mimipc
mimipc

Reputation: 1374

I found a page describing the greedy thing I was refering to in my comment : http://www.mspo.com/how-to/greed-in-apache-rewrite-rules.html

Upvotes: 1

Related Questions