Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 27th, 2008, 06:02 PM
t1mmie t1mmie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 t1mmie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 40 sec
Reputation Power: 0
Turning /x into /y/x ?

Sorry, I've read through the stickies and such but I STILL can't seem to figure out how I can do what I need to do here.

My .htaccess file is currently:

Code:
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]


Where the page is "/stair_covers", all I want to do is rewrite that into "non-slip/stair_covers".

Seems simple enough? I have everything in the same directory.

Thanks for your help!

Reply With Quote
  #2  
Old April 27th, 2008, 11:17 PM
Toxinhead's Avatar
Toxinhead Toxinhead is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 147 Toxinhead User rank is Corporal (100 - 500 Reputation Level)Toxinhead User rank is Corporal (100 - 500 Reputation Level)Toxinhead User rank is Corporal (100 - 500 Reputation Level)Toxinhead User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 17 h 34 m 28 sec
Reputation Power: 3
Send a message via MSN to Toxinhead
Quote:
Originally Posted by t1mmie
Code:
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]




Try this:
Code:
RewriteEngine on
RewriteRule ^non-slip/([-a-zA-Z0-9_]+)/?$ index.php?page=$1 [NC]


That will rewrite index.php?page="anything to www.domain.com/non-slip/anything/ .... hopefully

Reply With Quote
  #3  
Old April 28th, 2008, 11:54 AM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,124 jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 10 h 58 m 38 sec
Reputation Power: 717
Code:
RewriteRule ^stair_covers/?$ /non-slip/stair_covers [L]
__________________
# Jeremy

Explain your problem instead of asking how to do what you decided was the solution.

Reply With Quote
  #4  
Old April 28th, 2008, 04:06 PM
t1mmie t1mmie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 t1mmie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 40 sec
Reputation Power: 0
Thanks for replying guys.

I couldn't get Toxinhead's example working right, unfortunately.. and I'm not entirely sure it's what I want to achieve.

All of my files are in the main directory (apart from images and css), and after adding what your suggested jharnois, my .htaccess file now looks like this:
Code:
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^stair_covers/?$ /non-slip/stair_covers [L]


Is that correct? Only, now when I go to "/stair_covers" it returns a 404 saying that "non-slip/stair_covers" cannot be found. Am I doing something wrong?

The file doesn't actually have to be in a directory called /non-slip, does it? I though you could have it rewrite the url to pretty much anything you wanted, but I could be wrong :\

Just to clarify - I want to be able to link to "non-slip/stair_covers" instead of just linking to "/stair_covers".

Thanks guys

Reply With Quote
  #5  
Old April 28th, 2008, 04:51 PM
Toxinhead's Avatar
Toxinhead Toxinhead is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 147 Toxinhead User rank is Corporal (100 - 500 Reputation Level)Toxinhead User rank is Corporal (100 - 500 Reputation Level)Toxinhead User rank is Corporal (100 - 500 Reputation Level)Toxinhead User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 17 h 34 m 28 sec
Reputation Power: 3
Send a message via MSN to Toxinhead
Hey
Ohok so you want it linking to non-slip/stair_covers instead of "/stair_covers?

Does the folder /stair_covers exsist on your website?

Or are you getting the folder from this:
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]

Thanks

Reply With Quote
  #6  
Old April 28th, 2008, 04:55 PM
t1mmie t1mmie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 t1mmie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 40 sec
Reputation Power: 0
Quote:
Originally Posted by Toxinhead
Hey
Ohok so you want it linking to non-slip/stair_covers instead of "/stair_covers?

Does the folder /stair_covers exsist on your website?

Or are you getting the folder from this:
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]

Thanks


The only folders that exist are the main directory, /images, and /css. So yeah, it would be from that previous rule

Reply With Quote
  #7  
Old April 29th, 2008, 02:26 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,124 jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 10 h 58 m 38 sec
Reputation Power: 717
mod_rewrite takes a [usually] non-existent URL and rewrites it to an existing URL. So yes, the target in RewriteRule pattern target must exist (unless you rewrite it again, but ignore that b/c you're not doing that).

So if you want to link to /non-slip/stair_covers, which does not exist, but show the contents of /stair_covers, which does exist, mod_rewrite can do that. However, it cannot create files out of nothing and you can't rewrite to files that don't exist (unless you rewrite the rewrite, again, ignore for now).

So it sounds to me like you want to be able to link to /non-slip/stair_covers and show the results of /index.php?page=stair_covers or are you trying to show the results of /index.php?page=non-slip/stair_covers?

Please provide some additional examples of what you want to happen in this format:
Code:
/pseudo/address /index.php?page=address

Reply With Quote
  #8  
Old April 29th, 2008, 05:29 PM
t1mmie t1mmie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 t1mmie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 40 sec
Reputation Power: 0
Ok, initially (without any rewrite rules) the page would be called

Code:
index.php?page=stair_covers


This is rewritten using this rule:
Code:
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]


.. to look like
Code:
"domain.com/stair_covers"


But instead of looking like that, I want it to be:

Code:
"domain.com/non-slip/stair_covers"


But I only want it to be the case, for that page. The page called 'stair_covers'.

Hopefully that's clear now, and is feasible!

Reply With Quote
  #9  
Old April 30th, 2008, 07:06 AM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,124 jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 10 h 58 m 38 sec
Reputation Power: 717
I apologize for being picky, but you need to get your terminology and explanation correct; mod_rewrite does the reverse of what you're describing. It does not take /index.php?page=stair_covers and rewrite it to /non-slip/stair_covers, it takes /non-slip/stair_covers and rewrites it to /index.php?page=stair_covers. IOW, mod_rewrite takes non existent URLs and rewrites them to existing URLs, not the other way around. This is a small but important difference b/c 1) the only part of communication on a forum is text, and that's only a small part of communication, and 2) it means you have to change your links to point to /non-slip/stair_covers, and some people don't understand that.

So, to get what I believe you want:
Code:
RewriteRule ^non-slip/stair_covers/?$ /index.php?page=stair_covers [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]

Reply With Quote
  #10  
Old May 1st, 2008, 04:52 AM
t1mmie t1mmie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 t1mmie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 40 sec
Reputation Power: 0
It is all clear to me now, thank you jharnois

One more thing though, if I may - what must I now add to have it redirect to index.php?page=404, if a page does not exist?

Many thanks!

Reply With Quote
  #11  
Old May 1st, 2008, 08:12 AM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,124 jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level)jharnois User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 10 h 58 m 38 sec
Reputation Power: 717
That's a PHP question and should be asked in the PHP forum

You have to change index.php to send the proper header()s when $_GET['page'] is not found in the database (or however you're retrieving the information). I would start by reading the documentation and user comments on header() in the PHP documentation, trying a few things, and then posting the relevant PHP in that forum if you need help.

Reply With Quote
  #12  
Old May 1st, 2008, 08:59 AM
t1mmie t1mmie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 t1mmie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 39 m 40 sec
Reputation Power: 0
I was thinking of using the 301 redirect, but yeah ok, I'll look around anyway and consult the PHP forum if needs be ^_^

Thanks for your help

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > Turning /x into /y/x ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!