I\'d basically like to get
/path/file+name+with+plusses.mp3
to rewrite to
/path/file name with plusses.mp3
In m
I have a better one - with PHP :
.htaccess:
RewriteCond %{REQUEST_URI} ^/word/[^/]+$
RewriteRule ^word/(.*)$ http://example.com/special_redirect.php?q=$1 [L,QSA,R=301]
./special_redirect.php
<?php
$q = $_GET['q'];
$new = strtolower(convert_character($q));
//echo "$q | $new";
$location = "http://" . $new . ".example.com/";
//echo $location;
function convert_character($name) {
$patterns_raw = array('Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', 'ß');
foreach ($patterns_raw as $pattern_raw) {
$patterns[] = '/' . $pattern_raw . '/u';
}
$replacements = array('ae', 'ae', 'oe', 'oe', 'ue', 'ue', 'ss');
$new_name = preg_replace($patterns, $replacements, $name);
return $new_name;
}
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: $location" );
?>
This above copes with German umlaut chars but it is adaptable for the simpler cases of "_" to "-" and so on...
Well, I do have a solution, but I don't really like it... This will replace all underscores with dashes, and redirects with a 301 status code, which is the 'Moved permanently'. (of course you can use it to replace any other chars too)
Also, it should be the first rule (for ex in the .htaccess file) because the first line is a loop actually, which goes through all the rules again (because of the the N flag)
RewriteRule ^/redirect/from/([^_]*)\_(.*)$ /redirect/from/thisisthethingwedontneed$1-$2 [N,L]
RewriteCond %{REQUEST_URI} (thisisthethingwedontneed)+
RewriteRule (thisisthethingwedontneed)+(.*) /url/to/redirect/to/$2 [NC,QSA,R=301]
Explanation:
'redirect/form' : the base path or anything you want to redirect from. It should be included in the second part, to be able to match it at the next run of the loop
first part: 'replace (not underscore) followed by an underscore followed by (anything)' an capture the first and last part for later use
second part: insert some text what is likely not found in your urls before the captured first part, then append the first part, then the dash, then the second part
flags: N : after this, go ahead again, execute all rewrite rules again, but with the altered url L : if there was a match, stop here (the 2 flags together actually make the thing what you would expect from the first one.)
Condition for the next rule: execute the next rule only if the previously defined string can be found in the request uri, at least one times
First part: match and capture any occurrences of the funny string, and capture everything after it
Second part: append the second part to any path we want to redirect to (and forget about the funny string)
Flags: NC: case insensitive QSA: append any query string R=301: redirect with moved permanently
I am not entirely convinced mod_rewrite will solve this problem for you as the +
is a perfectly legal query string character. If you have Wordpress installed into the root of your website, it may be treating that portion of the url (PathInfo) as a query string parameter.
Try this rule:
RewriteRule ^([^+]*)\+(.*) $1\ $2 [N]