P - I hoped you'd show up
That's quite a compliment, thank you. From your prior responses, I know that you're working hard to learn mod_rewrite and have the basics down okay. The rest is all logic ... as you get to below.
P - I hope the OP doesn't mind me carrying on this thread (if so, just say and I'll butt out), but after investing a couple of hours reading articles about mod_rewrite, I'm now curious about the best way to do this.
It's fair to ask questions along the same line as the OP.
P - Are you saying that it is a bad idea to change "url.com/portfolio.html" into "url.com/portfolio/"
If so, why?
There are several reasons:
Doing so changes the folder level for internal links.
Doing so makes Apache (and visitors) believe that they are linking to a folder's DirectoryIndex.
Doing so has no benefit.
It just makes no sense (to me) at all!
P - I've just finished reading your tutorial (again). The first part was fairly straight forward. The rest made my head explode.
Bummer! :eek2: That must have hurt!
P - One important thing I took away from what you wrote however, is to be explicit in what you tell Apache to do (and not to do).
P - So, I guess these are the requirements.
- If a user requests url.com/portfolio.html, then rewrite the address in the address bar to url.com/portfolio/ (not sure about slash) and then serve the file
- If a user requests url.com/portfolio or url.com/porfolio/ redirect internally to url.com/portfolio.html
P - And these are the steps I would take to solve this problem:
- Test if the entire query string exactly matches portfolio.html
- If so rewrite the query string to portfolio/
- Check if the query string exactly matches portfolio/
- If so, redirect internally to portfolio.html
P - Can you tell me if that is a sensible approach and maybe the sections of your tutorial I should concentrate on to accomplish this?
The "Redirect TO New Format" section has the code to handle a "loopy redirection."
Pullo, IMHO, you're going about this all wrong. You're trying to redirect TO the folder then back to the file (loopy - it can be done safely but that's more advanced [and IS in the tutorial how to do that safely]).
My list (advanced):
- Order is critical!
- Strip file extension (.html) by
- Serve file with .html file extension by
I intentionally used pseudocode to leave the coding as an exercise for you but will be willing to help if you run into a roadblock (even with the "non-loopy code" in the tutorial).