BetaONE will rise again!


Reply
  #1  
Old 6th Jan 05, 01:52 AM
SlickVic78's Avatar
SlickVic78 SlickVic78 is offline
Senior Member
 
Join Date: Sep 2001
Location: New York, USA
Posts: 515
SlickVic78 is an unknown quantity at this point
Need Help With URL Manipulations.
Hello All,

I decided to try and play around with directives/parameters you can place within .htaccess within a directory on a web hosting server. I am looking to do the following and really have no clue (after looking through the vast amount of sites online) what to really use (since I am not sure what I am looking for).

This is what I would like to accomplish:

Change This: http://www.mydomain.com/index.php?pg=home
To This: http://www.mydomain.com/home

Obviously, the modified URL will act just like the original link so that I can easily use the pg variable within my code (since I have a few checks on the variable "pg").

Also, continuing with this same concept, would it be easy to pass multiple variables within the same URL (example: http://www.mydomain.com/index.php?pg=home&cmd=do)?

Any help would greatly be appreciated.

Thanks in advance!
-SlickVic78
__________________
  • Pentium 4 3.20GHz Processor
  • 1 Gig DDR 400MHz RAM
  • 100 Gig 7200 RPM Western Digital HDD
  • 80 Gig 7200 RPM Western Digital HDD
  • Lite-On LTR-52327S CD-RW Burner
  • Lite-On SOHW-1633S DVD Burner
  • ATI Radeon 9700 Pro
  • Sound Blaster Audigy
  • Microsoft Windows XP Pro SP-2
Reply With Quote
  #2  
Old 13th Jan 05, 02:30 AM
SlickVic78's Avatar
SlickVic78 SlickVic78 is offline
Senior Member
 
Join Date: Sep 2001
Location: New York, USA
Posts: 515
SlickVic78 is an unknown quantity at this point
I ended up finding out how to do what I wanted to do with this URL manipulation. Instead of doing the folder structure, I decided to go the file structure route. Both can easily be accomplished writing a few lines to the .htaccess of the folder you want to apply this to.

So far things are working very well.

Woot!

-SlickVic78
__________________
  • Pentium 4 3.20GHz Processor
  • 1 Gig DDR 400MHz RAM
  • 100 Gig 7200 RPM Western Digital HDD
  • 80 Gig 7200 RPM Western Digital HDD
  • Lite-On LTR-52327S CD-RW Burner
  • Lite-On SOHW-1633S DVD Burner
  • ATI Radeon 9700 Pro
  • Sound Blaster Audigy
  • Microsoft Windows XP Pro SP-2
Reply With Quote
  #3  
Old 14th Jan 05, 03:15 AM
war59312 war59312 is offline
BetaONE Supporter
 
Join Date: Jul 2001
Location: U.S.A
Posts: 2,220
war59312 has disabled reputation
Send a message via ICQ to war59312 Send a message via AIM to war59312 Send a message via MSN to war59312 Send a message via Yahoo to war59312
Can you post the code please.
__________________
Ad Muncher Usage Statistics for v4.7 Build 27105/1624
Adverts removed by Ad Muncher: 1,601,933
Approximate bandwidth saved: 12,515 MB
Counter started: April 2, 2003

Download: http://war59312.admuncher.com/download.shtml
Reply With Quote
  #4  
Old 14th Jan 05, 03:50 AM
SlickVic78's Avatar
SlickVic78 SlickVic78 is offline
Senior Member
 
Join Date: Sep 2001
Location: New York, USA
Posts: 515
SlickVic78 is an unknown quantity at this point
Hello war59312,

Sure thing. All it requires is a few lines within your .htaccess file and you are good to go.

Suppose you have a URL that looks like this:
To manipulate your URLs, simply add this code to your .htaccess file:
Code:
RewriteEngine On RewriteRule ^catalog-?([^-]+)-([^-]+)(.*)\.html$ /catalog$3.html?$1=$2 [QSA,N] RewriteRule ^catalog-?\.html$ /catalog.php [QSA,L]
The first rule loops until no name-value pair is available and the second rule calls the catalog.php if no name-value pair is available.

So you would use this URL instead:
[EDIT] Removed ".php" after catalog. [/EDIT]

You would then have to be sure that all your URLs on your page reflect the new URL format, and you should then be good to go.

If you would prefer the Folder Structure like:
Let me know and I'll be more than happy to share my findings.

-SlickVic78
__________________
  • Pentium 4 3.20GHz Processor
  • 1 Gig DDR 400MHz RAM
  • 100 Gig 7200 RPM Western Digital HDD
  • 80 Gig 7200 RPM Western Digital HDD
  • Lite-On LTR-52327S CD-RW Burner
  • Lite-On SOHW-1633S DVD Burner
  • ATI Radeon 9700 Pro
  • Sound Blaster Audigy
  • Microsoft Windows XP Pro SP-2

Last edited by SlickVic78 : 14th Jan 05 at 05:03 AM.
Reply With Quote
  #5  
Old 14th Jan 05, 04:12 AM
war59312 war59312 is offline
BetaONE Supporter
 
Join Date: Jul 2001
Location: U.S.A
Posts: 2,220
war59312 has disabled reputation
Send a message via ICQ to war59312 Send a message via AIM to war59312 Send a message via MSN to war59312 Send a message via Yahoo to war59312
Yea that would be great too.

Thanks a ton,
Will

PS: Bet this helps with google too.
__________________
Ad Muncher Usage Statistics for v4.7 Build 27105/1624
Adverts removed by Ad Muncher: 1,601,933
Approximate bandwidth saved: 12,515 MB
Counter started: April 2, 2003

Download: http://war59312.admuncher.com/download.shtml
Reply With Quote
  #6  
Old 14th Jan 05, 05:21 AM
SlickVic78's Avatar
SlickVic78 SlickVic78 is offline
Senior Member
 
Join Date: Sep 2001
Location: New York, USA
Posts: 515
SlickVic78 is an unknown quantity at this point
Quote:
Originally Posted by war59312
Yea that would be great too.

Thanks a ton,
Will

PS: Bet this helps with google too.
Hey Will,

It should help with all search engines. Google started indexing variables within the URL, but to play it on the safe side, it wouldn't hurt to use this method.

Please take note of the edit above. I had to correct the URL you would use if you were to apply the code in my last post.

Here is the code to place within you .htaccess if you want the folder structure. Remember though - since the URL is being re-written, your images may break because of the folder structure. I will comment on that later. Here is the code you would place in the .htaccess if you were to want folder structure URL manipulation:
Code:
RewriteEngine On RewriteRule ^catalog/([^/]+)/([^/]+)(.*)$ /catalog$3?$1=$2 [QSA,N] RewriteRule ^catalog/?$ /catalog.php [QSA,L]
The URL to use for this would be (using above example URL):
Now, the way to fix the image breakage, there are 2 ways:
  1. Have all your images with full paths (ex- http://www.mydomain.com/images/image.jpg)
  2. Add more lines to the .htaccess
Let's say you had an image directory (src="images/image.jpg") and a scripts directory (src="scripts/script.js") that needed to be adjusted with how many folders you are using in the URL - you would then use this:
Code:
RewriteRule ^.+(images|scripts)/(.*)$ /$1/$2 [L]
This would bring you back to the doc root for your images and scripts directory. This way it will stay consistant with no images or scripts breaking do to the changing of the URL structure.

If you do not modify this, you will end up with this as an example:
Where it should be:
Also, if you have more than 9 variable pairs (&something=something) within your URL and are running apache >1.3.28 or >2.0.45, you may want to add this line within your .htaccess:
Code:
RewriteOptions MaxRedirects=25
This is to increase the maximum number of redirects from the default value 10 to 25 (these are so called internal redirects). This is an apache prevention for endless loops.

All this I learned from Robert over at http://forum.modrewrite.com/. This guy was totally helpful and has gotten back to me with every question I threw at him.

I hope this helps you out Will as much as it did for me!

Enjoy!
-SlickVic78
__________________
  • Pentium 4 3.20GHz Processor
  • 1 Gig DDR 400MHz RAM
  • 100 Gig 7200 RPM Western Digital HDD
  • 80 Gig 7200 RPM Western Digital HDD
  • Lite-On LTR-52327S CD-RW Burner
  • Lite-On SOHW-1633S DVD Burner
  • ATI Radeon 9700 Pro
  • Sound Blaster Audigy
  • Microsoft Windows XP Pro SP-2
Reply With Quote
  #7  
Old 14th Jan 05, 06:03 AM
war59312 war59312 is offline
BetaONE Supporter
 
Join Date: Jul 2001
Location: U.S.A
Posts: 2,220
war59312 has disabled reputation
Send a message via ICQ to war59312 Send a message via AIM to war59312 Send a message via MSN to war59312 Send a message via Yahoo to war59312
Heck yea, thanks a ton.
__________________
Ad Muncher Usage Statistics for v4.7 Build 27105/1624
Adverts removed by Ad Muncher: 1,601,933
Approximate bandwidth saved: 12,515 MB
Counter started: April 2, 2003

Download: http://war59312.admuncher.com/download.shtml
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
URL redirect not working Darkwolven Feedback and Suggestions 5 26th Nov 04 10:17 AM
IE URL Spoofing Bug; SP2 Users Not Affected NewsBot NeoWin News 0 31st Oct 04 12:00 AM


All times are GMT +1. The time now is 12:01 PM.


Design by Vjacheslav Trushkin for phpBBStyles.com.
Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.