Forum Moderators: phranque

Message Too Old, No Replies

.htaccess help redirect dynamic url to static

         

buildersweb

12:04 pm on Apr 14, 2010 (gmt 0)

10+ Year Member



I have changed an old site from dynamic to static. I m about to upload it but i want to have first the urls from google to be redirected to the correct pages.

The Old url structure is :
http://www.example.com/testimonials.php?lang=gr
http://www.example.com/subcategory.php?subcatid=1&lang=gr
...

The new url will be
http://www.example.com/folder/folder1/page1.html
http://www.example.com/folder/folder2/page2.html
....

If i try this it will not work
redirect 301 /testimonials.php?lang=gr http://www.example.com/folder/folder1/page1.html


I read this [webmasterworld.com...]
and i believe that i have to change the above in order to achieve the correct redirect... Can anyone help me with this syntax .....

# Externally redirect client requests for old dynamic urls to equivalent new static urls
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?product=([^&]+)&color=([^&]+)&size=([^&]+)&texture=([^&]+)&maker=([^\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://example.com/product/%1/%2/%3/%4/%5? [R=301,L]


Thanks

[edited by: jdMorgan at 1:48 pm (utc) on Apr 14, 2010]
[edit reason] Please use example.com only. [/edit]

jdMorgan

1:56 pm on Apr 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because mod_rewrite has no way to "know" that folder1=testimonials and that folder2=subcategory, you will have to write one rule for each old URL that you wish to redirect; It won't be possible to use only one (or a few rule) to redirect all old URLs.

Alternately, you may wish to rewrite (not redirect) *all* old URLs to a script, which can look up the new URL in your database, and then generate the correct 301-redirect response to the client.

On the other hand, the only reason to do this kind of redirect is to speed up the removal of the old URLs from search engines. It is optional, and not required for your site to work. For this reason, you may wish to redirect only a few of the top-ranked and top-traffic old URLs, and leave the rest. Or you may not wish to do these redirects at all, and instead just wait for the old URLs to disappear from search listings on their own, as the search engines find, follow, and index the new links on your pages.

Jim

buildersweb

2:11 pm on Apr 14, 2010 (gmt 0)

10+ Year Member



Thanks for the quick responce !

I will do several rules if needed .... and i will remove the rest from the serch engines.

Can you please provide a correct rule that does the trick .. ? i will try then to copy it for the rest...

buildersweb

5:45 pm on Apr 16, 2010 (gmt 0)

10+ Year Member



Can someone give the right syntax .. Im going to change the site i want to be sure that this will do the redirect...

Thanks!

jdMorgan

1:40 am on Apr 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's one example:

# Externally redirect client requests for old dynamic urls to equivalent new static urls
#
# http://www.example.com/subcategory.php?subcatid=1&lang=gr -301-> http://www.example.com/folder/folder2/page2.html
#
RewriteCond %{QUERY_STRING} ^subcatid=1&lang=gr$
RewriteRule ^subcategory\.php$ http://www.example.com/folder/folder2/page2.html? [R=301,L]

Specific questions are welcome. See our Apache Forum Charter [webmasterworld.com] for more information.

Jim

buildersweb

10:49 am on May 24, 2010 (gmt 0)

10+ Year Member



I used the code and worked on an empty .htaccess for a static site... and it worked

Now i have the some urls like the previous (dynamic) and i want to convert it to static sef urls but in a dynamic site i have design in joomla

I used sh404sef to change the urls of joomla from non sef to sef urls like myurl.htm

Now i wanted also to redirect the urls that google has indexed from previous site and i m tring to fix that from .htaccess but i can not manage it ....


The problem is that i use the same rule but is not working ....

the htaccess of joomla is
##
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]

########## Begin - Joomla! core SEF Section
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

RewriteCond %{QUERY_STRING} ^catid=11&subcatid=7$
RewriteRule ^subcategory\.php$ http://www.example.com/Tours/half-day-tour.htm? [R=301,L]


At the end of this file i added this code
RewriteCond %{QUERY_STRING} ^catid=11&subcatid=7$
RewriteRule ^subcategory\.php$ http://www.example.com/Tours/half-day-tour.htm? [R=301,L]


but the redirect is not working ....

Any help?

[edited by: jdMorgan at 1:23 pm (utc) on May 24, 2010]
[edit reason] Do not post copyrighted material at WebmasterWorld [/edit]

g1smd

11:06 am on May 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Redirects must ALWAYS be listed before rewrites.

Change the order of your rules to comply with that.

jdMorgan

1:27 pm on May 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The RewriteConds in the "core SEF section" should also be re-arranged to put the -d and -f checks last. You may see a significant speed-up from this simple change.

For proper operation, put your access controls first, followed by all external redirects in order from most-specific patterns and conditions to least-specific patterns and conditions. Finish up with all of your internal rewrites, again ordered from most- to least-specific.

Jim