|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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! |
|
#2
|
||||
|
||||
|
Quote:
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 ![]() |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
||||
|
||||
|
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 |
|
#6
|
|||
|
|||
|
Quote:
The only folders that exist are the main directory, /images, and /css. So yeah, it would be from that previous rule ![]() |
|
#7
|
||||
|
||||
|
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 |
|
#8
|
|||
|
|||
|
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! |
|
#9
|
||||
|
||||
|
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] |
|
#10
|
|||
|
|||
|
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! |
|
#11
|
||||
|
||||
|
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. |
|
#12
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > Turning /x into /y/x ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|