I want to pass data through the url while using mod_rewrite. I read many links on stackoverflow and other sites but I can't find the solution.
The resulted URL is:
http://example.com/Path/logmanagement/view/1/?name=3&type=klik
print_r returns : Array ( [action] => logbeheer [do] => view [id] => 1 )
Currently I have this htaccess:
Options -Indexes
ServerSignature Off
RewriteEngine On
#RewriteBase /
##this part is what I tried##
RewriteCond %{QUERY_STRING} ^name=(\d+)&type=(\w+)$
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)$ index.php?action=$1&do=$2&id=$3&name=%1&type=%2
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/$ index.php?action=$1&do=$2&id=$3&name=%1&type=%2
##end this part##
# URL Filtering helps stop some hack attempts
#IF the URI contains a "http:"
RewriteCond %{QUERY_STRING} http\: [OR]
#OR if the URI contains a "["
RewriteCond %{QUERY_STRING} \[ [OR]
#OR if the URI contains a "]"
RewriteCond %{QUERY_STRING} \] [OR]
#OR if the URI contains a "<script>"
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#OR script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#OR any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^.*$ - [F,L]
# END Filtering
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z_0-9-]+)$ index.php?action=$1
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)$ index.php?action=$1&do=$2
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)$ index.php?action=$1&do=$2&id=$3
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)$ index.php?action=$1&do=$2&id=$3&id2=$4
RewriteRule ^([a-zA-Z_0-9-]+)/$ index.php?action=$1
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/$ index.php?action=$1&do=$2
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/$ index.php?action=$1&do=$2&id=$3
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/$ index.php?action=$1&do=$2&id=$3&id2=$4
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/([a-zA-Z_0-9-+]+)/$ index.php?action=$1&do=$2&id=$3&name=%1&type=%2
# Fixed upload issues for the milti file upload
SetEnvIfNoCase Content-Type "^multipart/form-data;" "MODSEC_NOPOSTBUFFERING=Do not buffer file uploads"
I want to pass 2 form fields throught the URL (name and type) to read it as GET.
Then you should add QSA flag to desired mor_rewrite rule.
RewriteRule ^(.*)/(.*)/$ /somefile.php?var1=$1&var2=$2 [QSA]
http://example.com/abc/def/?a=10&b=hello
print_r($_GET);
Array(
var1 = 'abc'
var2 = 'def'
a = '10'
b = 'hello'
);
Hope, this is what you was looking for.