Forum Moderators: phranque
# To externally redirect /example.com/foo.php?find=123 to example.com/dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\?check=([^&\s]+) [NC]
RewriteRule ^ %1/%2? [R=301,L]
# To internally forward /example.com/foo.php?find=123 to example.com/dir/foo
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?check=$2 [L,QSA]
# Remove .php extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
from
https://www.example.org/whatever.php?check=msn.com
to
https://www.example.org/whatever/msn.com
Right Now i get
https://www.example.org/whatever/msn.com%3f
[edited by: not2easy at 1:01 pm (utc) on Mar 22, 2023]
[edit reason] please use 'example' for domains [/edit]
# To externally redirect /example.com/foo.php?find=123 to example.com/dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\?check=([^&\s]+) [NC]
RewriteRule ^ %1/%2? [R=301,L]
# To externally redirect /dir/foo.php?find=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\?check=([^&\s]+)(?:&(\S+))? [NC]
RewriteRule ^ %1/%2?%3 [R=301,L]
# To externally redirect /dir/foo.php?find=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\?check=([^&\s]+)(?:&(\S+))? [NC]
RewriteRule ^ %1/%2?%3 [R=301,L]
# To internally forward /dir/foo/12 to /dir/foo.php?find=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?check=$2 [L,QSA]
# Remove .php extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Code solve issue with Captcha for contact form
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\s/(.+)\.php[^\s]* [NC]
RewriteRule ^ /%2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [QSA,NC,L]
RewriteCond %{QUERY_STRING} ^check=([^&]*)(?:&(.*))?
RewriteRule ^([^.]+)\.php https://www.example.com/$1/%2?%3 [R=301,L]
%{REQUEST_URI} !(actual|names|of|real|directories)
--again so the server doesn't have to go look.
https://www.example.com/test/whatever.comor https://www.example.com/test/111.111.111
RewriteCond %{QUERY_STRING} ^check=([^&]*)(?:&(.*))?
RewriteRule ^([^.]+)\.php https://www.example.com/$1/%2?%3 [R=301,L]
[edited by: not2easy at 10:34 am (utc) on Mar 23, 2023]
[edit reason] please use 'example' for domains [/edit]
Here is full code regarding that works right now:
You forgot below in code to add GET (as method used in form)
# To externally redirect /dir/foo.php?find=123 to /dir/foo
RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\?check=([^&\s]+)(?:&(\S+))? [NC]
RewriteRule ^ %1/%2?%3 [R=301,L]
# To internally forward /dir/foo/12 to /dir/foo.php?find=12
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/([^/]+)/?$ $1.php?check=$2 [L,QSA]
# Remove .php extension
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Code solve issue with Captcha for contact form
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\s/(.+)\.php[^\s]* [NC]
RewriteRule ^ /%2 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [QSA,NC,L]
except for very rare cases, the external redirects should precede the internal rewrites.
otherwise, you risk exposing internal urls to external requests.