Redirect URL with Query String using RedirectMatch
I'm trying to use RedirectMatch to redirect URLs with a question mark left over from an SEO plugin. Our vbulletin 4.2.5 forum is using Dragonbyte SEO to rewrite URLs but some external sites are still linking to the old URLs. We also have a strange issue with an equal sign being appended to some URLs which also breaks things. I've been trying to create redirect rules for these issues but everything I've tried seems to either cause an error or not work at all. I'd really appreciate any assistance I could get with this.
Example URL: http://subdomain.example.com/content/?123-My-Article-Title
Desired Redirect: http://subdomain.example.com/content/123-My-Article-Title.html
Live Server: LiteSpeed Test Server: Apache 2.4.27
example .htaccess attempts:
RewriteRule ^(\/content\/)\?([0-9]*[-a-z,A-Z]*)$ http://subdomain.example.com/$1$2.html [R=302, L]
RedirectMatch 302 /content/?([0-9]*[a-zA-Z-]*) http://subdomain.example.com/$1.html
1 answer
-
answered 2018-04-17 04:06
starkeen
You can not redirect querystring using
RedirectMatch
directive. You need to match against%{QUERY_STRING}
variable usingmod-rewrite
.RewriteEngine on RewriteCond %{QUERY_STRING} ^(.+)$ RewriteRule ^content/?$ http://Subdomain.example.com/content/%1.html? [L,R]
See also questions close to this topic
-
Extract words using regex
I have a string query and I want to match and extract specif words. when I have this word
word.EXACT
extract the container of this wordlike
MESH.EXACT("blood glucose monitoring")
extract the word"blood glucose monitoring"
- words.exact("N-Words") -> result
"N-Words"
- words.exact(N-Words) -> result
N-Words
Query_Input= (EMB.EXACT("insulin treatment")) and (MESH.EXACT("blood glucose monitoring")) OR "Self-Monitoring of Blood Glucose”
the output needs to be like that
Query_out=
"insulin treatment" "blood glucose monitoring" "Self-Monitoring of Blood Glucose”
this Demo has my regexp and my regex : https://regex101.com/r/rqpmXr/15
- words.exact("N-Words") -> result
-
CSV File Manipulation
Say I have two CSV files. The main file is complete with data on customers:
CODE, NAME, SURNAME, GROUP "A0001","Bo","Bamson","1" "A0002","Robert","Burnham","2" "A0003","Foo","Bar","2" ...
The second file contains only two fields:
CODE, GROUP "B0004","3" "A0003","1" "C0001","2" ...
By using the CODE field as a "key" the second file needs to replace the corresponding customer data in the main file (in this example "GROUP"). The main file should then look like this:
CODE, NAME, SURNAME, GROUP "A0001","Bo","Bamson","1" "A0002","Robert","Burnham","2" "A0003","Foo","Bar","1" ...
Customer "A0003" now has a GROUP of 1.
What would be the simplest way to implement this? I've been fiddling around with Notepad++ and regular expressions but I'm not sure if there's an obvious solution I'm missing.
-
How to send regex expression from JavaScript to PHP
I try to send the regular expression
\d+-\d+-\d+T\d+:\d+:\d+\+\d+:\d+\sINFO\s\(\d\):\sSTARTE\sKundenimport
to my PHP webserver.So I tried to Base64 encode the string before sending it.
Base64.encode(startRegex)
function test(logfile, startRegex, endRegex) { return $.ajax({ url: "ajax.php", type: "POST", data: { action: "getAllStrBetween", inputStr: logfile, startRegex: Base64.encode(startRegex), endRegex: Base64.encode(endRegex) } }); } /** * * Base64 encode / decode * http://www.webtoolkit.info/ **/ var Base64 = { // private property _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode : function (input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode : function (input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode : function (string) { string = string.replace(/\r\n/g,"\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode : function (utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while ( i < utftext.length ) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } }
I also used this code on PHP side to turn off magic quotes:
<?php if (get_magic_quotes_gpc()) { $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); while (list($key, $val) = each($process)) { foreach ($val as $k => $v) { unset($process[$key][$k]); if (is_array($v)) { $process[$key][stripslashes($k)] = $v; $process[] = &$process[$key][stripslashes($k)]; } else { $process[$key][stripslashes($k)] = stripslashes($v); } } } unset($process); } if (isset($_POST['startRegex'])) { $startRegex = base64_decode(filter_input(INPUT_POST, "startRegex")); } echo $startRegex; //Output: "d+-d+-d+Td+:d+:d++d+:d+sINFOs(d):sSTARTEsKundenimport"
But I get this output:
"d+-d+-d+Td+:d+:d++d+:d+sINFOs(d):sSTARTEsKundenimport"
Thanks in advance for any help.
-
.htaccess configuration for https redirect and client routing
I have Apache 2.4.27 and two problems:
1. redirect http -> https
2. SPA (Vue2) client routing without #
Solution for 1(it works):
RewriteEngine on RewriteCond %{HTTP_HOST} ^site\.com [NC] RewriteCond %{HTTP:X-Forwarded-Proto} ^http$ RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Solution for 2(Vue official recomendation):
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] </IfModule>
how to satisfy both conditions?
-
Unable to redirect to other url in apache
I have two Redhat Linux servers, say 'original' and 'demo'. Both have apache running on them. On original server, I have a link 'http://original.com/abc' on a page which I want redirect it to http://demo.com.
What I have done is-
Open httpd.conf on original server and added following lines and restarted apache service:
ProxyPass /abc http://demo.com/ ProxyPassReverse /abc http://demo.com/
But when I am trying to access http://original.com/abc, it is redirecting me to the original server i.e. on http://original.com (not on http://demo.com)
I have tried to find the solutions on various sites but unable to find out what the problem is.
Edit: Output of
curl -v http://original.com/abc
:curl -v http://original.com/abc * About to connect() to original.com port 80 (#0) * Trying 10.100.100.100... * Connected to original.com (10.100.100.100) port 80 (#0) > GET /demo HTTP/1.1 > User-Agent: curl/7.29.0 > Host: original.com > Accept: */* > < HTTP/1.1 302 Found < Date: Tue, 24 Apr 2018 06:30:23 GMT < Server: Apache-Coyote/1.1 < X-Frame-Options: SAMEORIGIN < Cache-Control: no-cache, no-store, max-age=0, must-revalidate < Pragma: no-cache < Expires: 0 < X-XSS-Protection: 1; mode=block < X-Frame-Options: SAMEORIGIN < X-Content-Type-Options: nosniff < Location: login.action < Content-Type: text/html; charset=UTF-8 < Content-Length: 0 < Set-Cookie: JSESSIONID=0BAA246C7F2505D2F5A0335CB0542CAA; Path=/; HttpOnly < * Connection #0 to host original.com left intact
Output of
curl -v http://demo.com/
:#curl -v http://demo.com * About to connect() to 10.100.100.101 port 80 (#0) * Trying 10.100.100.101... * Connected to 10.100.100.101 (10.100.100.101) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.29.0 > Host: demo.com > Accept: */* > < HTTP/1.1 302 Found < Server: Apache-Coyote/1.1 < Cache-Control: no-cache, no-store, max-age=0, must-revalidate < Pragma: no-cache < Expires: 0 < X-XSS-Protection: 1; mode=block < X-Frame-Options: SAMEORIGIN < X-Content-Type-Options: nosniff < Set-Cookie: JSESSIONID=FED19458459131F456D638EC57278C2A; Path=/; HttpOnly < Location: login.action < Content-Type: text/html < Content-Length: 0 < Date: Tue, 24 Apr 2018 06:31:47 GMT < * Connection #0 to host demo.com left intact
-
Apache Child process consume huge memory
"top" shows the result of how httpd-Child-process consume the memory. most Child process uses 400MB. I think this is too huge.
Usually, I know Child process consume the memory at most 50MB.
Do you know any good way to know why the child process uses huge memory?
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1039 nobody 20 0 32.7g 412m 55m S 0.0 0.3 0:50.76 httpd 10366 nobody 20 0 32.7g 411m 54m S 0.0 0.3 1:11.28 httpd 16115 nobody 20 0 32.7g 410m 53m S 0.0 0.3 0:44.23 httpd 26472 nobody 20 0 32.7g 410m 52m S 0.0 0.3 0:45.95 httpd ・・・・ ・・・・
-
htaccess Rewrite Friendly URLs
Can someone halp me making the following:
when typing: https://localhost/mysite/index.php?m=produktdetail&menutopid=1&menuid=7&menusubid=&id=21
I would like the url looking like:
https://localhost/mysite/produktdetail/1/7/21
I tryed the following with no success:
RewriteCond %{THE_REQUEST} \?m=([^&\s]+)&menutopid=([^&\s]+)&menuid=([^&\s]+)&menusubid=&id=([^&\s]+)? [NC] RewriteRule ^ /%1/%2/%3/%4? [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ /index.php?m=$1&menutopid=$2&menuid=$3&menusubid=&id=S4 [L,QSA,NC]
What am I doing wrong?!?
-
Redirect query dynamic string to path using htaccess
I am trying to rewrite dynamic query string to path something like this:
https://www.mysite.com.au/property-detail/?address=4-12-streetname-6000-WA&id=123456/
To
https://www.mysite.com.au/property-detail/4-12-streetname-6000-WA/123456/
Can you please help he acheive this using htaccess thank you!
-
.htaccess RewriteRule remove some url parts
I'm still new in htaccess and I want to learn it if possible but I need to finish my project first in school.
My original url is:
http://localhost/example/php/admin/
I want to rewrite it so it will only shows and also that's what will be need to write in url to access the url above:
http://localhost/example/admin/
is it possible with htaccess? also if you have a good advice where to learn htaccess, I want to learn if possible. thanks :)