Forum Moderators: phranque
I want the following url to be rewriten:
[111.222.333.444...]
to
[111.222.333.444...]
or more generaly:
How can I replace ALL given character with something else in the complete URL even if there are /../../ before the part it concerns?
My .htacces :
# REMOVING QUERY STRING
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_URI} .
RewriteRule (.*) c?%1
# TO LOWERCASE
RewriteCond %{REQUEST_URI} [A-Z]
RewriteCond %{REQUEST_URI} !\.(gif¦jpg¦jpeg¦png¦css¦js¦ico¦swf¦mov¦qt¦mp3¦rm¦mpg¦mpeg¦avi¦pdf¦doc)$
RewriteRule (.*) ${lc:$1} [R=301,L]
#SPACES AND QUOTES
RewriteRule ^(.*)\ ([^\ ].*)$ $1-$2 [E=rspace:yes,N]
RewriteRule ^(.*)\"([^\ ].*)$ $1$2 [E=rspace:yes,N]
# TRAILING SLASH
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ [111.222.333.444...] [L,R=301]
a url WITHOUT /c/ like
[111.222.333.444...] and gentleman"
returns:
[111.222.333.444...]
but WITH a trailing / it refuses to work:
[111.222.333.444...] and gentleman"/
returns:
[111.222.333.444...]
even
[111.222.333.444...] and gentleman"
does not rewrite my url
Any ideas?
I posted a case-conversion routine as part of a much larger piece of code [webmasterworld.com] in our forum library that may be of some help to you. But be advised that using mod_rewrite to do case-conversion and character substitution is *highly* inefficient. If you have other options like using a RewriteMap (as you did above with "${lc:$1}") or doing the character-substitution and redirects in a script, I highly-recommend those alternatives. Do be sure that you've got the "lc" lowercasing map defined, as it is not necessarily going to be available on any shared server.
Jim
[111.222.333.444...]
to
[111.222.333.444...]
but how to do so in .htaccess apache(2.0)?
Normally, you want the server to internally rewrite the browser's incoming HTTP request for the new URL-path /c/Biking/bike-tools to the server filepath /c/Biking/%22bike%20-%20tools%22
And then, if there are old links out on the web to the dynamic URL-path, you want the server to externally redirect incoming requests for the old URL-path /c/Biking/%22bike%20-%20tools%22 to the new URL http://example.com/c/Biking/%22bike%20-%20tools%22
Before doing either of these, the links on all of your pages must be changed to http://example.com/c/Biking/bike-tools. You must edit the HTML or modify the script that produces your HTML pages -- mod_rewrite cannot change your HTML.
Jim
We want the current google links (and the corresponding page rate) to be redirected to the new page.
So all urls google knows (like "bike - tools") have to be directed to "bike-tools" our new page.
This is only a temporary issue. Google reads the new page via a robot spider and the current stored in it's ranking list. Both have to be pointed to the same page. Otherwise 2 url are going to the same page and reduces the raking
That's why the spaces and quotes have to be deleted.
RewriteCond %{ENV:myURI} ^([^\"]*)(.*)$
RewriteRule . - [E=myURI:%1%2]
RewriteCond %{ENV:myURI} ^([^\ ]*)(.*)$
RewriteRule . - [E=myURI:%1-%2]
RewriteCond %{ENV:myURI} [" ]
RewriteRule . - [N]
NO RESULTS !
a hardcoded rewriterule:
RewriteRule [domain.com...] jacks" [domain.com...] [R=301,L]
doesnot work either. No url change :-(
The pattern should not contain http or the domain name.
RewriteRule cannot 'see' query strings. You need a RewriteCond for that.
Another major problem is that for most of your post you were asking for a 'rewrite' and at the last minute you have started to show code for a 'redirect'.
You need a redirect for any requests asking for the old URL so that the user is redirected to the new URL.
This other thread talks about both redirects and rewrites: [webmasterworld.com...]
I'm using Apache 2.0 on Linux RedHat 4
A gives me no problems to redirect to
[domain.com...]
B has to have as result:
[domain.com...]
But refuses
Either I do a redirect of the hardcoded url inside httpd.conf OR I have to have a piece of code to change in the QUERY_STING the spaces into dashes and delete the quotes
I prefer the second on, but I cannot find a solution.
So I also tried the hardcodes way.
already tried without positive result:
1. RewriteCond %{QUERY_STRING}^ObjectPath=/Shops/domain/Categories/Outdoor/"chairs\%20kids"$
RewriteRule ^nl_NL/$ http://example.com/c/outdoor/chairs-kids? [R=301,L]
=== it still shows the old url in address-bar
2. RewriteCond %{QUERY_STRING} ^ObjectPath=/Shops/domain/Categories/Outdoor/%22chairs%20kids%22"$
RewriteRule ^nl_NL/$ http://example.com/c/outdoor/chairs-kids? [R=301,L]
=== it still shows the old url in address-bar
3. RewriteCond %{QUERY_STRING} ^ObjectPath=/Shops/domain/Categories/Outdoor/"chairs kids"$
RewriteRule ^nl_NL/$ http://example.com/c/outdoor/chairs-kids? [R=301,L]
=== page error or all url (also otherones)
I'm running Apache 2.0 on Linux RedHat 4
Have you enabled the Options that mod_rewrite requires (either "Options +FollowSymLinks" or "Options +SymLinksIfOwnerMatch" as documented) and included the "RewriteEngine on" directive in your .htaccess file?
You might want to examine the actual HTTP requests by using the "Live HTTP Headers" add-on for Firefox. This might help to determine which characters are being encoded and which are not, and to determine whether any characters are getting double-encoded. For example: " --> %22 --> %2522
Jim
RewriteCond %{QUERY_STRING} ^ObjectPath=/Shops/domain/Categories/Outdoor/%22chairs\%20kids%22$
RewriteRule ^(.*)$ [domain.com...] [R=301,L]
# If character replacement not already in progress
RewriteCond %{ENV:Replace} !=Yes
# and if the client-requested URL-path is not in the relevant
# format or if it contains no escaped quotes or spaces
RewriteCond %{THE_REQUEST} !^[A-Z]+\ /[a-z]/[^/]+/[^%]*\%(25)*2[02][^\ ]*\ HTTP/
# then skip the next five rules
RewriteRule ^ - [S=5]
#
# Else if character replacement not already in progress and the client-requested URL does
# contain escaped quote or space characters, copy the client-requested URL-path to a user-
# defined variable so that we can work on it without triggering Apache's known multiple-
# consecutive-rewrite error, and set the "character-replacement-in-progress" flag
RewriteCond %{ENV:Replace} !=Yes
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([a-z]/[^/]+/[^%]*\%(25)*2[02][^\ ]*)\ HTTP/
RewriteRule ^ - [ENV=myURL:%1,E=Replace:Yes]
#
# Remove one escaped quote (if any) from the working copy of the client-requested URL-path
RewriteCond %{ENV:myURL} ^([a-z]/[^/]+/[^%]*)\%(25)*22([^\ ]*)\ HTTP/
RewriteRule ^ - [E=MyURL:%1%3]
#
# Replace one escaped space (if any) with a hyphen in the working copy of the client-requested URL-path
RewriteCond %{ENV:myURL} ^([a-z]/[^/]+/[^%]*)\%(25)*20([^\ ]*)\ HTTP/
RewriteRule ^ - [E=MyURL:%1-%3]
#
# (Note that either one or both of the two preceding rules will always be invoked if this section is executed)
#
# If the working copy of the client-requested URL-path still contains additional escaped
# quote or space characters, then restart mod_rewrite rule processing from the beginning
RewriteCond %{ENV:myURL} ^%{ENV:myURL} ^[a-z]/[^/]+/[^%]*\%(25)*2[02][^\ ]*\ HTTP/
RewruteRule ^ - [N]
#
# Else redirect the client to the cleaned-up URL
RewriteRule ^[a-z]/[^/]+/ http://www.example.com/%{ENV:myURL} [R=301,L]
You should place this code as close to the top of your existing rewriterules and .htaccess code as possible, consistent with the recommended practice of placing all external redirect rules first, in order from most-specific to least-specific, followed by all internal rewrites, again in order from most-specific to least-specific.
I can't guarantee that this is exactly what you need or even that it will work. I just typed it here, and though I eyeballed it several times for correctness, it's not tested. So no warranty... :)
At the very least, it should provide you with a fairly good start.
Jim
RewriteCond %{QUERY_STRING} ObjectPath=/ERIC$
RewriteRule (.*) [google.nl?...] [R=301,L]
dealing with request_uri works fine:
RewriteCond %{REQUEST_URI} /ERIC
RewriteRule (.*) [google.nl?...] [R=301,L]
Jim