Forum Moderators: phranque
I want to change some things in my urls, but I don't know how to redirect that pages, so I don't lose all my search engine indexed pages.
The issue is next:
My urls looks like this now:
http://www.example.com/categories/Ra%C4%8Dunala/Prijenosna-ra%C4%8Dunala/
And i want to change them so they look like this:
http://www.example.com/categories/Racunala/Prijenosna-racunala/
%C4%8D is a special Croatian char which is not able to show in browsers
The thing is that hex code %C4%8D may show once, or maybe 5-6 times, and all of them should be changed so it redirects to proper new url.
Thanks for help
First, if you want to change a URL, there's only one place you can do that: You have to change the links in the HTML on your pages. No incoming-request-processing trick on the server can 'change' a URL.
So you must edit your HTML pages or modify the script or database which produces the URLs used in links on your HTML pages.
Having done that, you then need to "re-connect" the new URLs to the same filepath+query string path inside the server that the old URL used to resolve to. This can be done on a URL-by-URL basis if the number of URLs is small, using one RewriteRule per new URL. Example:
RewriteRule ^categories/Racunala/Prijenosna-racunala/$ categories/Ra\%C4\%8Dunala/Prijenosna-ra\%C4\%8Dunala/ [NE,L]
Then there's a third step: If a client (browser or search engine robot) directly requests an old (accented) URL, then you should redirect that request to the new (un-accented) URL. This will 'recover' the traffic and ranking factors of the old URLs, and pass them to the new, as well as speeding up the process of getting your old URLs out of search engine listings. Example:
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /categories/Ra\%C4\%8Dunala/Prijenosna-ra\%C4\%8Dunala/\ HTTP/
RewriteRule ^categories/Ra.+Dunala/Prijenosna-ra.+Dunala/$ http://www.example.com/categories/Racunala/Prijenosna-racunala/$ [R=301,L]
If these old URLs don't have a lot of inbound links from other sites, this last step may not be needed; It just speeds up the search engines' updating of your old URLs to your new.
As you've likely noticed, I didn't mention using mod_rewrite to do any of the URL-conversion work; Since mod_rewrite is a specialized Apache directive-processing module and not a true 'scripting language,' it is not well-suited to complex jobs like character-set conversion/translation. In fact it's horribly inefficient at doing this kind of job. There is also the problem that if you remove this non-printing character from all URLs, mod_rewrite will have no way to "know" where it should re-insert those characters to form a correct server filepath.
Therefore, the best approach is to pass these URL-requests to a script that has more-powerful functions and that can access your database if necessary to convert/translate the URLs.
Jim
The thing is next. I can easily rewrite those URLs to look exactly how I want to in PHP. But, those new URLs are not indexed in google, and I want to redirect them.
There is over 1k URLs which should be checked, with various encoded chars, that what i showed is just an example, there could be link like this:
http://www.example.com/products/Prijenosno-ra%C4%8Dunalo-%C4%8Detiri
which will look like this if i make str_replace in PHP:
http://www.example.com/products/Prijenosno-racunalo-cetiri
and I need to redirect user from upper link to the down link.
I am total newb with apache, so the only way I can explain is in logic.
IF in link is %C4%8D, REPLACE %C4%8D with c, REDIRECT to a new link.