Forum Moderators: phranque

Message Too Old, No Replies

Rewriting URLs containing percent sign character

         

johnjames84

5:18 am on Mar 15, 2010 (gmt 0)

10+ Year Member



Hi,

I am hunting for a htaccess code to suppress/remove the %3F that occurs in my URL

http://www.example.com/index.php%3Foption=com_test&Itemid=3&view=show&id=6

to


http://www.example.com/index.php?option=com_test&Itemid=3&view=show&id=6

The %3F need to be changed to '?'. Can you please help

-James

g1smd

6:48 am on Mar 15, 2010 (gmt 0)

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



This is a Joomla install isn't it? Can I suggest you also look at URL rewriting?

The default Joomla install has multiple duplicate content issues, not least that there are mor4e than six different URLs that will show the root home page content.

johnjames84

7:41 am on Mar 15, 2010 (gmt 0)

10+ Year Member



Yes, it is a Joomla installation.

I was looking at URL rewriting but that is not helping me out here.

I believe we can solve this using the .htaccess file for sure, so can you suggest me some solution here?

-James

jdMorgan

3:08 pm on Mar 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(\%(25)*3[Ff]([^\ ]*))?\ HTTP/
RewriteRule ^index\.php http://www.example.com/?%3 [R=301,L]

In addition to correcting the "%3f"-encoded question mark, this also canonicalizes "/index.php" to "/", as generally recommended. Be sure you don't link to "/index.php" from within your own site -- all links should be to just "/" --with or without appended query string-- before using this code.

Or, if you want to retain the "index.php" URL-path (not recommended for SEO/usability reasons):

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php\%(25)*3[Ff]([^\ ]*)\ HTTP/
RewriteRule ^index\.php http://www.example.com/index.php?%2 [R=301,L]

The "(25)*" subpatterns in the RewriteConds above allow for correcting multiply-encoded "?" symbols, as in "%252f" or "%25252F", in addition so the singly-encoded "%2f" or "%2F".

Jim

g1smd

7:29 pm on Mar 16, 2010 (gmt 0)

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



Whilst the correct URL for the root page should be just / there's complications in simply removing index.php from the URL, because the root index page can also be accessed through
/index.php?option=com_frontpage
and
/index.php?option=com_frontpage&Itemid=1
requiring more complicated redirects than you might first imagine.

All of the internal URLs have more parameters and complexity than is really necessary, and the vast majority of rewriting solutions do not properly get to the heart of the problem. You can spot a Joomla install simply by the ugly overcomplicated URLs, even after rewriting. I'm going through this with a ZenCart install at the moment, and it's a total nightmare.