homepage Welcome to WebmasterWorld Guest from 23.23.8.131
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
How do redirect URLs not containing any alphabets to alphabets involve
Redirect page-id query-based URLs to keyword-based URLs
sweetguyzzz

5+ Year Member



 
Msg#: 4100805 posted 2:38 am on Mar 19, 2010 (gmt 0)

Hello,

I have to redirect my dynamic pages to static one and with adding keywords to it, so please tell me that it is possible to redirect URL from a text which is not present in the URLs. See Example

My pages are like
example.com/page.php?pageid=2

Now I want to redirect this URL to
example.com/page-2-somekeywords.html

I created a script which will only redirect example.com/page.php?pageid=2 to the example.com/page-2.html

I do not know how to add these keywords in URL and I do some changes in my script but that does not help
My Script is:

RewriteCond %{QUERY_STRING} ^pageid=([0-9]*)
RewriteRule ^page\.php$ http://www.example.com/page-%1\.html? [R=301,L]

#If the condition true go here and redirect this URl
RewriteRule ^page-([0-9]*).html$ http://www.example.com/page.php?submit=submit&pageid=$1 [L]

Thanks
Please reply fast, I am thankful to all responders in advance.

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4100805 posted 9:55 pm on Mar 20, 2010 (gmt 0)

> so please tell me that it is possible to redirect URL from a text which is not present in the URLs. See Example.

Sorry, no, it is not possible, unless you want to write a separate rule for each "pageid" value. If you have hundreds of pageid values, this would result in a large .htaccess or config file, and likely in a *very* slow site.

The usual solution is to rewrite *all* pageid URLs to a script, which can then open your database, look up the new URL by using the client-requested pageid, and then generate a 301-moved permanently redirect to the new "SEO friendly" URL. Therefore, only one rule is required in your .htaccess/config file, and all of the "heavy work" is done by your script, which has access to the information needed to associate pageid with the string that you want in the new URL.

Jim

sweetguyzzz

5+ Year Member



 
Msg#: 4100805 posted 6:30 am on Mar 21, 2010 (gmt 0)

Thanks JIm for your good reply.

So you are telling that if I am using PHP so I use header(); to redirected my all pages to these new URLs. But I am not sure that this header will make permanent redirect or temporary ?

Thanks again
Haider

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4100805 posted 1:42 pm on Mar 21, 2010 (gmt 0)

Your PHP code must be written to return both the proper server status code and the proper header text. The code has been posted in our PHP forum several times, and it is not at all complicated -- Only one or two lines of PHP code are needed to return a proper 301-Moved Permanently or 302-Found redirect, 404-Not Found, or 410-Gone response.

Jim

sweetguyzzz

5+ Year Member



 
Msg#: 4100805 posted 4:53 pm on Mar 21, 2010 (gmt 0)

Very much thanks Jim, I found the proper redirection method in webmasters PHP forum. Again thanks to you.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved