Current location: Hot Scripts Forums » Programming Languages » PHP » Url Htaccess Re-write

Url Htaccess Re-write

Reply
  #1  
Old 06-19-09, 07:34 PM
smithygotlost smithygotlost is offline
Coding Addict
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 345
Thanks: 7
Thanked 0 Times in 0 Posts
Url Htaccess Re-write

Heya guys

got a question about htaccess url re-writing, what i wanna do is take a url like profile.php?id=(number)&hash=(hashnumber)

but wanna make it something like

/profile/number/hash

how would i go about doing this ?? hints tips or an example code

thanks
Mike
__________________
Make People Friendly Say " Thanks "
Reply With Quote
  #2  
Old 06-19-09, 09:10 PM
Jcbones Jcbones is offline
Coding Addict
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 280
Thanks: 3
Thanked 5 Times in 5 Posts

Last edited by Jcbones; 06-19-09 at 09:39 PM.
Reply With Quote
  #3  
Old 06-20-09, 01:51 PM
smithygotlost smithygotlost is offline
Coding Addict
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 345
Thanks: 7
Thanked 0 Times in 0 Posts
um, ok well i got this

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^profile/([0-9]+)/([^/]+) http://eveninghorrors.com/profile.php?id=$1&hash=$2 [NC]
however its make all my images and things get from http://eveninghorrors.com/profile/id/image.type

how can i get round this ??


Thanks
mike
__________________
Make People Friendly Say " Thanks "
Reply With Quote
  #4  
Old 06-20-09, 02:30 PM
Jcbones Jcbones is offline
Coding Addict
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 280
Thanks: 3
Thanked 5 Times in 5 Posts
From another forum,

Quote:
Hello all,

After a couple of late nights of intense focus on URI rewriting I am now ready to show you my 'code baby' up for some scrutiny. I am not after a ready made fix, but some helpful pointers to adapt the code if neccesary would be great. I can work from there, but keep in mind that until 3 days ago my knowledge was 0. Thanks to all for all previous useful posts&answers and tutorials at webmasterworld.

This is what I wanted:

rewrite

http://www.example.com/year1969
plus
http://www.example.com/summerof/year1969

to

http://www.example.com/index.php?page=year1969
and
http://www.example.com/index.php?page=summerof_year1969
resp.

And this is how I achieved this:

Options +FollowSymLinks
rewriteEngine on

rewriteCond %{REQUEST_URI}!(\.(gif¦jpg¦css)¦/index\.php)$
rewriteRule ^([^/]+)/?$ /index\.php?page=$1
rewriteRule ^([^/]+)/([^/]+)/?$ /index\.php?page=$1_$2 [L]

Although all my links to imgs and the css are relative to the server I did run into some problems with some of my images not being shown. Only when I moved the images to a deeper directory (from /images/ to /images/images2/ and changed the link correspondingly they were shown [strange].

Could someone shine a light on why only the deeper dir. structure for images would work? Also, any comments on the rewrite will be greatly appreciated.

Thanks

Skylla


Not sure where your non-working images were originally located, but here's a guess: Because a rewriteCond applies only to the first rewriteRule that follows it, your second rule is unconditional, and will rewrite images in any first-level subdirectory (i.e. /SubdirectoryName/ImageName.ImageType) to /index.php?page=SubdirectoryName_ImageName.ImageTyp e

There are several ways to fix this problem. Here are three of them.

Repeat the rewriteCond:

rewriteCond %{REQUEST_URI} !(\.(gif¦jpg¦css)$¦^/index\.php$)
rewriteRule ^([^/]+)/?$ /index\.php?page=$1
#
rewriteCond %{REQUEST_URI} !(\.(gif¦jpg¦css)$¦^/index\.php$)
rewriteRule ^([^/]+)/([^/]+)/?$ /index\.php?page=$1_$2 [L]

-or-

Stop mod_rewrite processing & exit if image or index.php requested:

rewriteRule \.(gif¦jpg¦css)$¦^index\.php$ - [L]
#
rewriteRule ^([^/]+)/?$ /index\.php?page=$1
rewriteRule ^([^/]+)/([^/]+)/?$ /index\.php?page=$1_$2 [L]

-or-

Skip only these two rules if image or index.php requested; Resume execution of any subsequent rules:

rewriteRule \.(gif¦jpg¦css)$¦^index\.php$ - [S=2]
#
rewriteRule ^([^/]+)/?$ /index\.php?page=$1
rewriteRule ^([^/]+)/([^/]+)/?$ /index\.php?page=$1_$2 [L]

Replace the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

Jim
Hope this helps.
Reply With Quote
  #5  
Old 06-20-09, 03:12 PM
smithygotlost smithygotlost is offline
Coding Addict
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 345
Thanks: 7
Thanked 0 Times in 0 Posts
not really :S stil cant make head or tails of it, all im thinking is that if the htaccess re-writes that file from

profile/id/hash

to

profile.php?id=id&hash=hash

then why dont the images sort them selves i need some serious help with this coding

Thanks
Mike
__________________
Make People Friendly Say " Thanks "
Reply With Quote
  #6  
Old 06-20-09, 06:08 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 499
Thanks: 0
Thanked 0 Times in 0 Posts
Try adding this ....

rewriteEngine on
RewriteBase /
Reply With Quote
  #7  
Old 06-20-09, 06:30 PM
smithygotlost smithygotlost is offline
Coding Addict
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 345
Thanks: 7
Thanked 0 Times in 0 Posts
no difference atall unless i added it wrong

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^profile/([0-9]+)/([^/]+) http://eveninghorrors.com/profile.php?id=$1&hash=$2 [NC]
__________________
Make People Friendly Say " Thanks "
Reply With Quote
  #8  
Old 06-20-09, 06:46 PM
Nico's Avatar
Nico Nico is online now
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 7,536
Thanks: 5
Thanked 20 Times in 18 Posts
Remove the domain name including the http part.
Reply With Quote
  #9  
Old 06-20-09, 06:49 PM
smithygotlost smithygotlost is offline
Coding Addict
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 345
Thanks: 7
Thanked 0 Times in 0 Posts
same difference

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^profile/([0-9]+)/([^/]+) profile.php?id=$1&hash=$2 [NC]
__________________
Make People Friendly Say " Thanks "
Reply With Quote
  #10  
Old 06-20-09, 07:12 PM
smithygotlost smithygotlost is offline
Coding Addict
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 345
Thanks: 7
Thanked 0 Times in 0 Posts
sorry to be so short was on phone lol, i appreciate your help just wish i could get my head around it any other ideas ?
__________________
Make People Friendly Say " Thanks "
Reply With Quote
Reply

Bookmarks


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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
htaccess conflict with similar url kiko08 Web Servers 0 11-08-07 01:53 AM
htaccess and problems passing variables in the URL. Nico Web Servers 1 01-07-07 06:31 AM
URL Rewriting...htaccess? landing Web Servers 4 07-28-06 10:05 AM
Need help: Html script- url linking nyjumpman23 HTML/XHTML/XML 5 09-28-05 10:19 PM
The Reasons Why do you Need URL Rewriting MODULE to Enchance your Web? handry PHP 11 08-05-05 08:32 AM


All times are GMT -5. The time now is 10:17 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2 (Unregistered)