homepage Welcome to WebmasterWorld Guest from 54.147.248.118
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Need to Use Redirect and Remove Hash from URL
Need help Redirecting Googles Site Pages and Removing Hash Part of URL.
acimag

5+ Year Member



 
Msg#: 4053968 posted 8:42 pm on Jan 4, 2010 (gmt 0)

Current URL Reads:
http://www.example.com/productdetail.php?ID=343&Hash=7aea1e538ecda42d48db6474e652e158d0ddba0f

I want to manually enter all of the redirected pages because none of the URL's are search engine Friendly. Meaning

I may want:
=========
http://www.example.com/productdetail.php?ID=343&Hash=7aea1e538ecda42d48db6474e652e158d0ddba0f to redirect to

http://www.example.com/343/Taxi-Tracker.html
=========
and maybe another page:
=========
http://www.example.com/productdetail.php?ID=3333&Hash=7aea1e538ecda42d48db6474e652e158d0ddba0f to redirect to

http://www.example.com/3333/Taxi-Cab-Technology.html
=========

I will do this line by line because from here on in I will be able to write my Rewrite rule and never have to worry about this again. It is just to correct all the screw ups of there last web company using a crappy CMS system.

The Hash needs to leave forever.

I'm figuring that the RewriteRule would look like:
(I Can do it once of 100 times.)
RewriteRule ^([^/]*)/([^/]*)\.html$ /?ID=$1&NAME=$2 [L]

OR Should I do all of these per each one...

RewriteRule ^([^/]*)/Taxi-Tracker\.html$ /?ID=$1 [L] <-- for Taxi-Tracker Page
RewriteRule ^([^/]*)/Taxi-Cab-Technology\.html$ /?ID=$1 [L] <-- for Taxi Car Technology Page

 

jdMorgan

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



 
Msg#: 4053968 posted 4:33 pm on Jan 5, 2010 (gmt 0)

You will have to do them one at a time, because the URL http://www.example.com/343/Taxi-Tracker.html does not contain the Hash number, and there is therefore no way for mod_rewrite to know what it should be unless you hard-code it into the rule substitution.

Note that your statement of the direction of redirection is backwards when compared to your code, and that this is an internal rewrite, not an external redirect. Your code is internally rewriting "friendly" .html URLs to "unfriendly" script filepaths plus query strings.

If your intent is to clean up "unfriendly" URLs listed in search results, then you do need a redirect in addition to the above internal rewrite. However, the code to do this redirection is complicated by the fact that you will have to check to be sure that the "unfriendly" path is being requested directly by a client and not as a result of the internal rewrite function needed to implement the "friendly" URLs. If you don't check for direct client requests before redirecting, then you'll end up with an "infinite" rewrite/redirect loop, because the internal-rewrite rule will rewrite friendly URLs to the unfriendly script file-path, and then the external-redirect rule will redirect that request right back again. This will loop until the server throws an error and gives up or until the browser redirection limit is reached and it gives up.

Because of all the problems -- asymmetrical friendly/unfriendly URLs forcing case-by-case URL-by-URL handling, plus the complications of loop avoidance, you might be happier rewriting only 'friendly' URLs to your script, and then handling all 'unfriendly' URL client requests inside your script.

The advantage is that since the script has database access, it can use one simple function to take an unfriendly client-requested URL, go look up the "Taxi-Tracker" title based on the hash in that requested URL, and generate a 301 redirect to the correct friendly URL -- and all such unfriendly-URL-to-friendly-URL redirects can be handled with just a few lines of code.

Jim

acimag

5+ Year Member



 
Msg#: 4053968 posted 8:05 pm on Jan 5, 2010 (gmt 0)

Well Luckily there is 47 pages I need to re-write so it's not a big deal.

I tried using:

redirect 301 /productdetail.php?ID=7433&Hash=bfc187wbaf1daf0a [domain.com...]

and

RewriteRule ^productdetail.php?ID=7433&Hash=bfc187wbaf1daf0a [domain.com...] [R=301]

Both did not work. any help?

acimag

5+ Year Member



 
Msg#: 4053968 posted 8:20 pm on Jan 5, 2010 (gmt 0)

So im trying this:

RewriteCond %{THE_REQUEST} ^productdetail.php?ID=7433(&(Hash=[^\ ]*))?\ HTTP/
RewriteRule ^$ [domain.com...] [R=301,L]

am I mixing things up?

jdMorgan

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



 
Msg#: 4053968 posted 8:29 pm on Jan 5, 2010 (gmt 0)

The literal period and "?" in the RewriteCond pattern both need to be escaped, and %3 is undefined.

You don't need a back-reference to "hash" according to what you've posted above. So remove the inner layer of parentheses from the RewriteCond pattern and drop the undefined %3 reference from the RewriteRule substitution.

Jim

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