Closed Thread Icon

Topic awaiting preservation: Stupid mod_rewrite....... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=25302" title="Pages that link to Topic awaiting preservation: Stupid mod_rewrite....... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Stupid mod_rewrite....... <span class="small">(Page 1 of 1)</span>\

 
CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-21-2005 16:50

I have an index page that uses SSI to pop in other pages from a different directory.

Here is what I have on the index page:

code:
switch ($_GET['link']){

case extcab:
$page = "pages/extcab.php";
break;

case cabspec:
$page = "pages/cabspec.php";
break;
default:
$page = "pages/main.php";



so, all the SSI stuff is coming from the "pages" directory. However, there are some that are coming from directories in the "pages" directory.

So, in the above code, I also have:

code:
case faq:
$page = "pages/faq/index.php";
break;

case cabFAQ:
$page = "pages/faq/cab.php";
break;

case kitFAQ:
$page = "pages/faq/kit.php";
break;



So, instead of having the sloppy URL showing and plus our customers have a hard time remembering the funky URL's (bookmark maybe ), I'd like to use mod_rewrite to change this. But, aside from having the occasional 505 error, I can't get it to do anything.

Documentation on what is going on with mod_rewrite is cryptic at best to my feeble mind. Any and all help would be greatly appreciated

Thanks in advance!

Later,

C:\

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-21-2005 17:55

the relevant parts from the much posted grail .htaccess:

code:
RewriteEngine On
#the index. You probably could just do DirectoryIndex page.php
RewriteRule ^$ /page.php
#rewrite numbers to call /page.php, passing the number in id=, and append everything else
RewriteRule ^([0-9]+) /page.php?g_mode=show&id=$1&%{QUERY_STRING} [L]
#probably what you want. Rewrite any word to redirect to page.php, otherwise, pretty much as above
RewriteRule ^([a-zA-z]{1}[[a-zA-z\ 0-9]*)$ /page.php?g_mode=special&id=$1&%{QUERY_STRING} [L]


So long,

->Tyberius Prime

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-21-2005 18:39

well, that is almost exactly as what I was doing earlier. The URL does not get rewritten and the index.php page pulls up a 404.

i have searched the FAQ here and other places, so I am doing some work. I just don't get the syntax even after reading the apache site about a million times.

I'll mess around with it and see if i can get it working. thanks for the help

Later,

C:\

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-21-2005 19:44

Stick a ,R into that [L] bracket, and see where you're actually being redirected to.

Syntax is simple.
RewriteRule MatchingRegexps UrlToBeServed

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-21-2005 20:07

no......didn't work. same thing. Index.php pulls up a 404 and nothing happens on the other pages.

syntax might be simple to some, but sure, it's easy once you know

Later,

C:\

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-21-2005 20:09

did it not change the url in your browser window at all when you added the [R]?

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-21-2005 20:52

nope........

Later,

C:\

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-22-2005 08:24

well... care to post your current .htaccess?

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-22-2005 14:26

well.........it's exactly what you posted above with this also

code:
RewriteEngine On
RewriteRule ^$ /page.php
RewriteRule ^([a-zA-z]{1}[[a-zA-z\ 0-9]*)$ /page.php?g_mode=special&id=$1&%{QUERY_STRING} [R]

#added this for the custom 404 page
ErrorDocument 404 http://www.mojotone.com/index.php?link=error



I also tried it with the other Rewrite rule:

code:
RewriteRule ^([0-9]+) /page.php?g_mode=show&id=$1&%{QUERY_STRING} [R]



as well as both and then just the one above.

thanks for the help.

Later,

C:\

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-22-2005 14:28

I might also add that the links to the SSI pages are called by the typical index.php?link=faq


just calling them that way. Don't think that matters but it doesn't hurt to post it

Later,

C:\

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 03-22-2005 16:10

CPrompt,

Have you looked at your error log to see if any errors are being generated when you try to access the page using these Rewrite rules?



.

-- not necessarily stoned... just beautiful.

Emperor
Maniac (V) Inmate

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 03-22-2005 18:37

OK lets take a step back from this.

This code:

quote:
RewriteRule ^$ /page.php[R]



Can't really work.

You also don't need this: {QUERY_STRING} or if you do you need to add in QSA to the squared brackets at the end i.e. [R,QSA]

--------------------
So what you need to do is write down what you want to do because this will virtually write your .htaccess statement.

So lets say you want:

/faq/
/links/

to map to:

/pages.php?page=faq
/pages.php?page=links

so you'd go with:

code:
RewriteEngine On
RewriteBase /
RewriteRule (faq|links) /pages.php?page=$1 [L]



but you may want to make this more general:

code:
RewriteEngine On
RewriteBase /
RewriteRule ([a-zA-z0-9_]+)^(\.php) /pages.php?page=$1 [L]



See also some discussion here:

http://www.gurusnetwork.com/discussion/thread/3020/

I'm afraid the key to good .htaccess is planning out what you want and then fiddling with it for a while.

It can also depend on your server (again see the GN discussion).

___________________
Emps

The Emperor dot org | Justice for Pat Richard | FAQs: Emperor | Site Reviews | Reception Room

if I went 'round saying I was an Emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!

(Edited by Emperor on 03-22-2005 18:38)

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-22-2005 19:32

you do have a file called page.php, do you?

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-22-2005 19:45
quote:
Tyberius Prime said:

you do have a file called page.php, do you?




nope. thought that was a little weird but I just figured that it was just generating a page.php in the URL. Kind of part of the Rewrite.

I have a pages directory with some pages in it and then I also have directories within the pages directory as well.

Anyway, I am gonna check out the discussion at GN because I am not real sure what the mod_rewrite actually does and how it works. Like I said above, the documentation I have read is sometimes cryptic at best *to me*.

So, let me take a look at this as a fresh start and see what I can figure out what's going on.

Thanks for the help.

Later,

C:\

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-22-2005 23:57

well, it redirects to a file called page.php - if you don't have such a file, it's going to cause a 404, obviously.

Emperor
Maniac (V) Inmate

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 03-23-2005 02:06

CPrompt: Yes well that'll do it

As I said write down what you want mapping to where and work out the felxibility you will need and the statement will start writing itself.

___________________
Emps

The Emperor dot org | Justice for Pat Richard | FAQs: Emperor | Site Reviews | Reception Room

if I went 'round saying I was an Emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-23-2005 02:27

I realized that it was trying to access a page called page.php, so I changed it to index and still nothing.

I have tried to take Emp's advice and map it out. Still nothing. Read the stuff at Guru's and the links that were provided there.......not working.
I'll mess with it some more and see what happens. Right now, besides either nothing, a 404 or the ocassional 500 error........not doing too well....

I have the directories written down and what I want them to do, so I guess at this point it just a matter of fiddling around with it, reading and re-reading documents........

oh well.........

thanks for the help

Later,

C:\

Emperor
Maniac (V) Inmate

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 03-23-2005 04:56

CPrompt: If you throw an example of what you have sketched out and the examples you have tried to get working I'll have a look at them and see if there is anything that stands out.

Did you try the Multiviews trick I mentioned at the GN?

___________________
Emps

The Emperor dot org | Justice for Pat Richard | FAQs: Emperor | Site Reviews | Reception Room

if I went 'round saying I was an Emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 03-23-2005 06:35

Hmmmm....

shouldn't

code:
RewriteRule ([a-zA-z0-9_]+)^(\.php)         /pages.php?page=$1 [L]


be

code:
RewriteRule ([a-zA-Z0-9_]+)^(\.php)         /pages.php?page=$1 [L]



Emperor
Maniac (V) Inmate

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 03-23-2005 06:40

Pugz: Thanks for spotting my #cough# deliberate mistake

___________________
Emps

The Emperor dot org | Justice for Pat Richard | FAQs: Emperor | Site Reviews | Reception Room

if I went 'round saying I was an Emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-23-2005 16:16

Emps, thanks for the offer. This is really boggling my brain (which doesn't take much ). What you posted as the "more general solution" really should work, but I'm screwing up somewhere. I have tried the Multiview trick to no avail.

Here is the layout of my directories:

pages (which contains most of the pages that are SSI'd)
pages/surplus (pages that just pertain to surplus items which are updated about once a month)
pages/faq (just general FAQ stuff)


The pages directory has stuff like cabspec.php, covers.php, privacy.php, etc...
The pages/surplus directory just has pages in like caps.php, connectors.php, etc...
The pages/faq directory has just three pages (index.php, kitFAQ.php and cab.php)

So here is what I want the mod_rewrite to do. If an SSI'd page is pulled in from any directory, I would like it to have the URL like:
http://www.mojotone.com/links. Which is pulled in from /pages/links.php so the url right now looks like http://www.mojotone.com/index.php?link=links I would like it to just be http://www.mojotone.com/links

Same goes for the other pages. Take the surplus pages for example. Right now, the surplus transformers are pulled in from the directory "pages/surplus/connectors.php" So the url looks like http://www.mojotone.com/index.php?link=connectors. I would like to just be http://www.mojotone.com/surplus/connectors

Hope this makes sense. I stayed up a little too late working on this and some other stuff..........

Click around on the site and that might give you a better idea of what I have and what I want to do.

All the pages are SSI'd from the /pages directory. The surplus is pulled from /pages/surplus and the FAQ are pulled from /pages/faq

I really want to get rid of the ugly index.php?link=links and so forth

NOW...let me just ask one stupid question. Where in my directories should this particular .htaccess reside? root or in the pages directory? I've tried both and nothing. As for what I have tried for the RewriteRule...everything mentioned above as well as some from a sitepoint article

Thanks for all your help guys.......sorry this is such a long drawn out thing but I am at least starting to understand mod_rewrite a little better I think.

Much appreciated!

Later,

C:\

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-23-2005 16:18

sorry.....one more thing. Should the links to the pages be changed from index.php?link=links to something like /links/ or something?

thanks

Later,

C:\

Emperor
Maniac (V) Inmate

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 03-23-2005 21:58

Last question first: With this non-destructive linking (i.e. the mod_rewrite just sends things on to the right destination) then old links will work just fine but for consistency I'd recommend changing the sites internal links to work with the new system.

On the first example lts keep things simple:

code:
RewriteEngine On
RewriteBase /
RewriteRule (links|faq) /index.php?link=$1 [L]



That should work - if it doesn't then there is a problem elsewhere (unless I've screwed up ).

On this:

quote:
Same goes for the other pages. Take the surplus pages for example. Right now, the surplus transformers are pulled in from the directory "pages/surplus/connectors.php" So the url looks like http://www.mojotone.com/index.php?link=connectors. I would like to just be http://www.mojotone.com/surplus/connectors



I'd recommend you keep things simple so I'd go for:

http://www.mojotone.com/connectors/
or:
http://www.mojotone.com/surplus_connectors/

If you already have a surplus folder then that could make things complicated (as you can start getting into loops and generating server errors).

If you want something like that then you'd really have to do:

http://www.mojotone.com/surplus/connectors

mapping to:

http://www.mojotone.com/surplus/index.php?link=connectors

And that rather starts defeating the purpose of your system.

You really need to distill things down to a simple and felxible linking system that is still logical for people. It might be you really want:

/links/something/
/surplus/something/
/faq/something/

which is easy enough to do:

code:
RewriteEngine On
RewriteBase /
RewriteRule (links|faq|surplus)(/)?([a-zA-Z0-9_]*) /index.php?link=$1&sub_link=$3 [L]



but that is something else to consider.

___________________
Emps

The Emperor dot org | Justice for Pat Richard | FAQs: Emperor | Site Reviews | Reception Room

if I went 'round saying I was an Emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!

(Edited by Emperor on 03-23-2005 21:59)

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-24-2005 02:02

Emps, this looks just like what I want

I have to say.......I'm a freakin idiot. I just noticed that the end of the mod_rewrite rule (i.e. /index.php?link=$1), I left it as (/index.php?page=$1)

so 1/2 of this topic could have been solved had I just paid attention to that. However, I feel that I have a much better grasp on how to layout what I want for the mod_rewrite now. This will be of great use in the future too.

Right now, my server is having some mySQL and FTP problems it seems as I can't access either of them. I just hope my database's are not screwed up when things come back online.........*sigh*

Thanks so much for the help and the explinations. I guess my day is done since the remote servers are having some problems. Thanks!!!

Later,

C:\

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-24-2005 22:15

well finally after my hosts server went through an obvious nasty DOS.......i got to test it out.

It works, but there is one thing. Here is my .htaccess file

code:
RewriteEngine On
RewriteBase /
RewriteRule (links|tips|faq|contact|news|caps|connectors|gcandt|pots|speakers) /index.php?link=$1 [L]



Now.........since I am no expert (obviously) there has to be a better way rather than listing all the pages seperatley. I tried this:

code:
RewriteRule ([a-zA-Z0-9_]+)^(\.php)        /index.php?link=$1 [L]



but that didn't work at all. So I am sure that I am really missing the point of the regular expression stuff in that line. I'll take a look at the apache documents again, but at any rate, I got it working thanks to you guys!

Later,

C:\



(Edited by CPrompt on 03-24-2005 22:16)

Emperor
Maniac (V) Inmate

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 03-25-2005 01:58

CPrompt: Good to see it is working fine.

I tend to use the OR (|) to keep tighter control over things but I think you'll be fine without so you could go for a general one like:

code:
RewriteRule ([a-zA-Z0-9_]+)        /index.php?link=$1 [L]



Hmmmmmmmm now I think about it that will potentially cause you problems as it will try and adjust everything including things like:

/graphics/my_graphics.gif

So then you'd need to start adding things back in to disallow them, etc. leading to a mor complex statement. It depends on which is less work - if this:

quote:
links|tips|faq|contact|news|caps|connectors|gcandt|pots|speakers



is all you'll need and you won't keep having to update the list all the time then I'd go with that - if it ain't broke.....

___________________
Emps

The Emperor dot org | Justice for Pat Richard | FAQs: Emperor | Site Reviews | Reception Room

if I went 'round saying I was an Emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-25-2005 02:23

well.......it's really not that big of a pain in the ass really. It was more of a general question as opposed to anything else.


that might be why some of my images are not showing up? thought it might be a problem with the server.........
so...........this all in all could be a problem anyway as I have to have multiple directories that hold images.

hmmmmmmmmm............

Later,

C:\

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 03-30-2005 18:39

alrighty........back at it. Rewrote some of my index page and shifted some stuff around.

Still haven't had much luck getting this thing to work which is why I am probably determined to get it.

Here is the switch statement calling the pages:

code:
switch ($_GET['link']){

/*main pages*/
case 'links':
$page = "pages/links.php";
$title = ". : Welcome to Mojo Tone . com! : . : Mojo Links";
break;

case 'contact':
$page = "pages/contact.php";
$title = ". : Welcome to Mojo Tone . com! : . : Contact Mojo";
break;

case 'tips':
$page = "pages/tips.php";
$title = ". : Welcome to Mojo Tone . com! : . : Mojo Tech Tips";
break;

/*sepecials*/
case 'specials':
if ($sublink == extcab){
$page = "pages/extcab.php";
$title = ". : Welcome to Mojo Tone . com! : . : Mojo Extension Cabinet";
}elseif ($sublink == cabspecial){ /*this is currently the 3x10 cab*/
$page = "pages/cabspec.php";
$title = ". : Welcome to Mojo Tone . com! : . : Mojo 3x12 Extension Cabinet";
}elseif ($sublink == coverspecial){ /*those o so great deals on covers*/
$page = "pages/coverspecial.php";
$title = ". : Welcome to Mojo Tone . com! : . : Covers";
}elseif ($sublink == weeklyspecials){ /*this is the ebay stuff*/
$page = "pages/specials.php";
$title = ". :Welcome to Mojo Tone . com! : . : Mojo Cabinet Specials";
}
break;
/*End Specials*/



and so on and so forth with that.

Calling the pages like:

code:
<a class="menuButton" href="index.php?link=faq">FAQ</a>

or

<a class="menuItem" href="index.php?link=surplus&sublink=speakers">Speakers</a>




.htaccess file which right now resides in the root folder of my subdomain

code:
RewriteEngine  on
Options +MultiViews
RewriteBase /
RewriteRule (links|contact|tips|privacy|email|testimonies|plugin|error|specials|surplus|showcase|faq)(/)([a-zA-Z0-9_]*) /index.php?link=$1sublink=$3 [L]




Aint workin a bit now. Had it working.....lost it.......now nothing. When it was working, it was taking out my images so I had to go back and figure out what else to do.

Got any clue what I can do?

Later,

C:\

« BackwardsOnwards »

Show Forum Drop Down Menu