Forum Moderators: phranque
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^news\/news\-archives\/?(.*)$ "http\:\/\/example\.com\/$1" [N]
RewriteRule (.*)e28099(.*)? $1 [R=301,L] RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^news\/news\-archives\/?(.*)$ "http\:\/\/example\.com\/$1" [N]
RewriteRule (.*)e28099(.*)? $1$2 [R=301,L] http://example.com/childrens-home-fills-patients-needs/news-archives/childrens-home-fills-patients-needs/ the canonical is set up and seems to work so that everythings directed to http://example.com...so can the 2nd RewriteCond can be dropped?
So that works for replacing the phrase, but then part of the url gets repeated.
Modified Code:
<snip, see above about repeating Conditions>
RewriteRule ^news\/news\-archives\/?(.*)$ "http\:\/\/example\.com\/$1" [N]
RewriteRule (.*)e28099(.*)? $1$2 [R=301,L]
Result:
{ http://example.com/news/news-archives/childrene28099s-home-fills-patientse28099-needs }
http://example.com/childrens-home-fills-patients-needs/news-archives/childrens-home-fills-patients-needs/
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule (.*)e28099(.*) $1$2 [N]
RewriteRule ^news/news-archives/(.*) /$1 [R=301,L] news/ if you're editing httpd.conf (preferable) rather than .htaccess. RewriteRule e28099 /fix-this.php [L] RewriteCond %{THE_REQUEST} !e28099 1. Extract the requested URL
2. Extract the requested path from that URL
3. String replace e28099 with nothing
4. Prepend protocol and www hostname to the new string
5. Send 301 HEADER does the string e28099 occur in any other URLs (not under the target hostname)? If not, you can simply leave off the conditions.
The form
(.*)e28099
is always a bit iffy. Are there any real-life limits to what might come before "e28099"? Put them in the rule, and non-matching requests will be out of there all the sooner.
Unless your name is jdMorgan, do not use the [N] flag. Instead, rearrange your rules:
FIRST rule for requests containing both
THEN two rules for requests containing one pattern or the other
how did it get there? did your cat walk across the keyboard?
Targets of RewriteRules don't need quotation marks.
That little phrase was the replacement for an apostrophe.
RewriteRule ^news/news-archives/(.*)e28099(.*)e28099(.*)$ http\:\/\/example\.org\/$1$2$3 [R=301,L]
RewriteRule ^news/news-archives/(.*)e28099(.*)$ http\:\/\/example\.org\/$1$2 [R=301,L]
RewriteRule ^news/news-archives/(.*)?$ http\:\/\/example\.org\/$1? [R=301,L] [edited by: phranque at 12:58 am (utc) on Sep 2, 2013]
[edit reason] exemplified domain [/edit]
there is no need to escape anything in the Substitution string.
you should remove all those backslashes.
[edited by: incrediBILL at 10:33 pm (utc) on Sep 4, 2013]
[edit reason] fixed typo [/edit]