Forum Moderators: phranque

Message Too Old, No Replies

htaccess URL redirect with percentage sign

htaccess URL redirect percentage

         

sananthv

6:03 am on Aug 4, 2010 (gmt 0)

10+ Year Member



Hi

I recently launched an updated version of my site. For non percentage URL's I am using "redirect" command to redirect URL's.

Currently I am redirecting all URL's which has a percentage sign to a perticular directory. This is because google has indexed some of my joomla site links that have percentage signs. The command i have used is

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^%?\ ]*\%
RewriteRule ^. [domain...] [R=301,L]

Now I have a situation where I want to redirect different URL's with percentage signs to different locations. Example

domain/folder%10two/index.php to domain/folderthree/index.php

and

domain/folder%10four/index.php to domain/folderfive/index.php

How should my code look like. Appreciate the help.

jdMorgan

2:51 pm on Aug 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Redirect domain/folder%10two/index.php to domain/folderthree/index.php :

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /folder\%10two/(index\.php)?\ HTTP/
RewriteRule ^. http://example.com/folderthree/ [R=301,L]

Note that you could avoid having to use one rule for each URL if you kept the same "number" in the new URL. That is, redirect folder%10two to foldertwo and folder%10three to folderthree instead of changing the number.

In that case, only one rule would be required for all "folders." For example :

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /folder\%10([a-z]+)/(index\.php)?\ HTTP/
RewriteRule ^. http://example.com/folder%1/ [R=301,L]

-or-

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /folder\%10([^/]+)/(index\.php)?\ HTTP/
RewriteRule ^. http://example.com/folder%1/ [R=301,L]

Also note that I did not include the "index.php" URL-path in the new URL, and that I made it optional in the RewriteCond pattern. We generally recommend against 'exposing' your site's technology either by redirecting to /index.<filetype> or by linking to it, because the technology/filetype might change, requiring you to change all of your URLs again -- something to be avoided if you care about search ranking and user experience on your site.

Instead, link and redirect only to "/" and use DirectoryIndex to map "/" in any directory to /index.php in that same directory (if this is not already done in the existing server config) using

DirectoryIndex index.php

Jim