0

Can someone help me again regarding this rewrite module,

with this rules

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) $1.php [QSA,L] 

with this rules, i can get the requested url www.example.com/test to www.example.com/test.php but how can i get following url www.example.com/test/test2/test3/test4 to www.example.com/test.php

i tried

RewriteRule (.*)/?$ $1.php [QSA,L]

don't laugh at me... i actually tried

RewriteRule (.*)/(.*)/(.*)/(.*)$ $1.php [QSA,L] 

and this works for this link

www.example.com/test/test2/test3/test4 to www.example.com/test.php

but, not for this one...

www.example.com/test to www.example.com/test.php

i'm using explode on Php cause i don't know how many parameters, that i need, if it is only 2 parameters, and this rules should be work.

RewriteRule ^(.+/)?([^/]*)$ p.php?s=%1&p=$2 [QSA,L,NC]

i did keep checking every similiar questions, which appear on the right, but i don't see any solution yet.

h4uw1n3
  • 31
  • 4

1 Answers1

0

You were creating an endless redirect. Try this checking for .php in the request. Also if you're not pulling the slashes the Apache would redirect to a non-existent index.php inside of some folder.

Example 1

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/ $1.php [QSA,L]

This takes the first directory matched and pulls it into the query string.

www.example.com/file/param1/param2/param3 shows this www.example.com/file.php

Example 2

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/(.*)$ $1.php?params=$2 [QSA,L]

This takes the first directory matched and pulls it into the query string. The rest of the URI is added as a parameter

www.example.com/file/param1/param2/param3 shows this www.example.com/file.php?params=param1/param2/param3

Example 3

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/?([^/.]+)?/?([^/.]+)?/?([^/.]+)?$ $1.php?p1=$2&p2=$3&p3=$4 [QSA,L]

www.example.com/file/param1/param2/param3 shows this www.example.com/file.php?p1=param1&p2=param2&p3=param3


Note: [QSA] keeps the existing parameters, so &original_parameter=param is appended to the rewritten query string.

AbsoluteƵERØ
  • 7,816
  • 2
  • 24
  • 35
  • thanks for the respone, but as i know, it will redirect all the request to the file test.php, isn't it? but what i want actually the first value behind the slash for the script file and then the rest will ignored. for example www.example.com/file/param1/param2/param3 to this www.example.com/file.php – h4uw1n3 May 08 '13 at 07:50
  • i tried this website http://www.generateit.net/mod-rewrite/ it give a results RewriteRule ^([^/]*)/([^/]*)$ $1.php?params=$2 [L] for this www.example.com/file/param1/param2/param3 to this www.example.com/file.php?params=param1/param2/param3 but it doesn't work. any other idea? – h4uw1n3 May 08 '13 at 07:53
  • awesome... that is a quick respone, anyway example 2 works for the url www.example.com/file/ and www.example.com/file/params/params, but not for the www.example.com/file and then i looked on your third example, i add a "?" like this.. RewriteRule ^([^/.]+)/?(.*)$ $1.php?params=$2 [QSA,L]... it's done... great!! thanks a lot.... too bad i can't vote up ur answer.... – h4uw1n3 May 08 '13 at 09:25