+ Start a Discussion
Abhilash Mishra 13Abhilash Mishra 13 

How to rewrite URL Links that are Generated By Javascripts

Hello,
I need to use URL rewriting for My site.

How ever the rewriter class only rewrites whats written using   $page or URLFOR() methods.
Like : 
<apex:outputlink value="{!URLFOR($page.pagename,null,[pageid='asdvsv'])}"> This is rewritabale link</apex:outputlink>

this also works fine:
 
<a href="{!URLFOR($page.pagename,null,[pageid='asdvsv'])}"> This is rewritabale link</a>

how ever when it comes to use a simple string to specify URL. It failes poorly.
 
<a href="/pagename?pageid=sdsfv"> This fails in rewriting</a>

the above links are generated as a part of javascript output.

Is there any way or work around to make them rewritable too.

Please Help.
Best Answer chosen by Abhilash Mishra 13
Abhilash Mishra 13Abhilash Mishra 13
Well I have sorted this out , you have to give the  SEO  Friendly URL directly and It will be inverse mapped. when using dynamic links as in javascript

like if your url is 
/pagename?pageid='dsdsdsdvsa'
 which become SEO friendly as /pagename/mypage.

you need to use /pagename/mypage. directly  in dynamic links.  other wise you must use
{!URLFOR($page.pagename,null,[pageid='asdvsv'])}" which will convert this to the same URL friendly URL

All Answers

Magesh Mani YadavMagesh Mani Yadav
Hi Abhilash,

You need to apend '/apex' for the href.
Can you try the below one
<a href="/apex/pagename?pageid=sdsfv"> This fails in rewriting</a>

 
Abhilash Mishra 13Abhilash Mishra 13
Hi Magesh,

Not working !!!
Magesh Mani YadavMagesh Mani Yadav
can you provide me what error r u getting?
Abhilash Mishra 13Abhilash Mishra 13
There is know error Its simply not working.

Like here  : http://sfecom-developer-edition.ap2.force.com/

the first link  uses :  
<apex:outputLink value="{!URLFOR($page.testindexpage,null,[pageid='sdasdvg'])}">this is written USING URL FOR Method </apex:outputLink>


 
the second 

 
<a href="/apex/testindexpage?pageid=sdasdvg">this is written using /apex/testindexpage?pageid=sdasdvg</a>


 
Abhilash Mishra 13Abhilash Mishra 13
Well I have sorted this out , you have to give the  SEO  Friendly URL directly and It will be inverse mapped. when using dynamic links as in javascript

like if your url is 
/pagename?pageid='dsdsdsdvsa'
 which become SEO friendly as /pagename/mypage.

you need to use /pagename/mypage. directly  in dynamic links.  other wise you must use
{!URLFOR($page.pagename,null,[pageid='asdvsv'])}" which will convert this to the same URL friendly URL
This was selected as the best answer