With this url http://www.example.com/cp/pending/thepage, when i $_GET['p']; i should get thepage returned. Nothing is being returned, How do i solve this?
Here is the mod rewrite.
RewriteRule ^cp/([A-Za-z0-9-]+)(&type=[A-Za-z0-9-]+)?(/[A-Za-z0-9-]+)?(&to=[A-Za-z0-9-]+)?(&r=[A-Za-z0-9-]+)?(&g=[A-Za-z0-9-]+)?(&page=[A-Za-z0-9-]+)?/?$ /cp.php?o=$1&type=$2&c=$3&p=$4&r=$5&g=$6&page=$7 [L]
Here is php
$p = $_GET['p'];
echo $p;
The query string is not part of the URL.
Your code should be like the following:
RewriteCond %{QUERY_STRING} RegexHere
RewriteRule URLRegexHere NewURL
If you use any part of the URL to create a new query string, you need to use the [QSA] flag to append the other parameters. E.g:
RewriteRule ^cp/pending/([^/])/?$ page.php?page=$1 [L,QSA]
More on Mod_Rewrite here.
Also, just as $n back-references are for patterns matched in the RewriteRule regex, %n back-references are for pattern matched in the RewriteCond regex.
Related
Have tried a lot of RewriteRule, even the previous suggested posts. Unfortunately, none works. Any help appreciated.
This will replace all %22 with " in the query string:
RewriteCond %{QUERY_STRING} ^(.*)\%22(.*)$
RewriteRule ^(.*)$ /$1?%1"%2 [L,R]
However, the & is used to separate query string parameters, so if you start with:
?abc=%22def%22&xyz=123
It'll change it to:
?abc="def"&xyz=123
which means the parameters will be
abc=
quot;def
quot;
xyz=123
You probably want to escape the & so that doesn't happen:
RewriteCond %{QUERY_STRING} ^(.*)\%22(.*)$
RewriteRule ^(.*)$ /$1?%1\%26quot;%2 [L,R,NE]
I'm trying to get the following path: /faculty/index.php?PID=FirstLast&type=alpha
To rewrite to this: /faculty/FirstLast
Am I correct to assume the following would be acceptable to put in .htaccess?
# Rewrite old URLS
RewriteCond %{QUERY_STRING} ^PID=([0-9a-zA-Z]*)$
RewriteRule ^/faculty/index.php$ /faculty/%1 [R=302,L]
I'm okay to throw away any other query string variables. I'm applying these rules at the .htaccess file level. This project is a migration from an older system into Drupal.
Outcome:
My .htaccess looks like
# Rewrite old URLS
RewriteCond %{QUERY_STRING} PID=([0-9a-zA-Z]*)
RewriteRule ^faculty/ /faculty/%1/? [R=301,L]
RewriteCond %{QUERY_STRING} vidID=([0-9]*)
RewriteRule ^videos/ /video/id/%1/? [R=301,L]
I also found this wonderful tool -- a mod_rewrite tester
http://htaccess.madewithlove.be/
All good!
Try this instead:
RewriteRule ^faculty/index.php$ /faculty/%1? [R=302,L]
The leading slash is not in the URI-path tested in the rule, so can't be in the regex either.
As the query is automatically appended to the substitution URL (passed through unchanged) unless a new query is created in the rule, the trailing question mark ? erases the existing query string when the rule is used.
I have a liitle mod_rewrite problem.
I have index.php (in root directory) which contains simple href link:
Novice
When I click on Novice, redirects me on novice.php file (which is mod_rewrited, that doesn't look like novice.php?query=this-is-something in URL, but looks like novice/this-is-something (this-is-something is my query)) The problem is, when I'm trying to GET "this-is-something" query in novice.php file.
I'm getting this query in novice.php file like that:
if (isset($_GET['query'])){
$query=$_GET['query'];
echo $query;
}else{
echo 'Null parameters.';
}
But it outputs just 0
But when I'm passing numbers in href link, like that:
Novice
The output in novice.php file is correct: 2131
I have code in my .htaccess like that:
RewriteRule ^novice/([^/\.]+)/?$ novice.php?query=$1 [L]
So what am I doing wrong in mod_rewrite, that i can get numbers through $_GET method, but I can not get string or charachters through $_GET?
I found solution by myself.
I've just changed "query" word at the end of RewriteRule ^novice/([^/.]+)/?$ novice.php?query=$1 [L]
to
"blabla" word -> RewriteRule ^novice/([^/.]+)/?$ novice.php?blabla=$1 [L]
And then works everything... Very strange...
if (isset($_GET['blabla'])){
$blabla=$_GET['blabla'];
echo $blabla;
}else{
echo 'Null parameters.';
}
It echo's now the parameter this-is-something.. But still don't know what was the problem.. I've just changed the name of variable "query" which was containing parameter "this-is-something"..
Btw if someone is interested: my .htaccess looks like this:
Options +FollowSymLinks
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://localhost/local_ageo.si/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://localhost/local_ageo.si/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
RewriteRule ^novice/([^/\.]+)/?$ novice.php?blabla=$1 [L]
I need the URl http://mydomain.com/careers to go to http://mydomain.com/#!/careers
For what it's worth I've tried numerours variations around this with no success
RewriteCond %{REQUEST_URI} !^/careers$
RewriteRule (.*) /#!/careers [QSA,L]
Can anyone help?
"!" in your RewriteCond line means "not"...
Also, "[QSA,L]" means:
L means this is last rule (processing terminates after matching this one) and
QSA means query string append
But, becase R flag was not specified, this is done by sub-request and not a redirect, so the actual URL in your browser does not change...
Try this:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/careers$
RewriteRule (.*) /#!/careers [R,L,QSA]
Hope this helps
RewriteCond %{REQUEST_URI} !^/?ping.php
RewriteRule ^/\?(.*)$ ping.php?url=$1 [L]
i am trying to match any character that follows /?
www.mysite.com/?someurl.com
instead it keeps loading the index.html !
You cannot match the query string with mod_rewrite, but if you still want to pass it on, you can add %{QUERY_STRING} to the resultant url, for example
RewriteRule ^.*$ ping.php?url=%{QUERY_STRING} [L]