Jump to content

SaranacLake

Members
  • Posts

    648
  • Joined

  • Last visited

Everything posted by SaranacLake

  1. This simple photo site that I am *trying* to build for my co-workers is a total of 7 pages... index.php menu.php photo-gallery.php photo-details.php access-denied.php page-not-found.php config.php I guess I could hide the .php for my two error scripts in addition to menu.php
  2. But "2019-holiday-party" is part of the pretty URL. If I take that out then I get a "Page Not Found" error because my variable will be blank as seen below... RewriteCond %{REQUEST_FILENAME} !-f RewriteRule client1/gallery/(.*)$ client1/gallery/photo-gallery.php?gallery-id=$1 Hopefully you picked up on the difference highlighted in red in my last post?? By adding back in [L,R=301] at least thing load properly, but then all f that aggravation to create a mod_rewrite to allow a pretty URl was for not?! I thought I was pretty good with mod_rewrites, but I have spent all day staring at my code and trying different things and re-reading my code and I just can't figure out what the problem is, because I swear what I have looks right?!
  3. I thought I answered your question. This mini website will only support php files. I want a pretty URL always (e.g. "/client1/menu") but if a user modified the URL to (e.g. "/client1/menu.php") then things should still work. (That is what I thought you were asking.) This site is purely PHP as is my other website. No HTML or TXT or whatever. Does that answer your question?
  4. Sorry, have been multi-tasking. I am retracting my earlier comment, and ask you to look at this again... **************************************************** SCENARIO #1: In this scenario I have... RewriteCond %{REQUEST_FILENAME} !-f RewriteRule client1/gallery/(.*)$ client1/gallery/photo-gallery.php?gallery-id=$1 [L,R=301] When I run this, it goes to the correct photo-gallery.php page HOWEVER, the URL is NOT correct... www.mysite.com/client1/gallery/photo-gallery.php?gallery-id=2019-holiday-party It should be... www.mysite.com/client1/gallery/2019-holiday-party **************************************************** SCENARIO #2: In this scenario I have... RewriteCond %{REQUEST_FILENAME} !-f RewriteRule client1/gallery/(.*)$ client1/gallery/photo-gallery.php?gallery-id=$1 When I run this, it goes to the correct photo-gallery.php page HOWEVER, the URL is NOT correct... www.mysite.com/client1/gallery/2019-holiday-party/?gallery-id=2019-holiday-party It should be... www.mysite.com/client1/gallery/2019-holiday-party In either scenario, with or without a [L,R=301] my pretty URL is getting screwed up!! WHY??
  5. My original intent was to allow a pretty URL in the address bar and then redirect to a formal menu.php URL. If a user hacked the address bar and typed in "menu.php" then it would be nice if my mod_rewrite supported this. For this particular script, I will not have any query strings.
  6. Scratch my P.S. message above - I was on a confernce call at work and misread things. However, in my previous message I asked why my pretty URL is not remaining in the address bar. And you are making me work extra hard to figure out this whole {L,R=301] thing! Show some mercy!! 😉
  7. @requinix, P.S. If I remove [L,R=301] from my mod_rewrite, I get this funkiness... When my browser redirects, the URL is an amalgamation of things like this... /client/gallery/photo-gallery.php?gallery-id=2019-holiday-party What is going on here? The first half looks good /client/gallery but what is happening with the rest photo-gallery.php?gallery-id=2019-holiday-party ??? Again, I am expecting to see this in the address bar: /client1/gallery/2019-holiday-party
  8. I missed your reply on this more pressing issue... I'm not entirely sure I understood your lesson and the correct answer. Please help me with this one!
  9. If I want to go from /client1/menu to /client1/menu.php then how about... RewriteCond <can you help me figure out what goes here?> RewriteRule client1/menu$ client1/menu.php [R=301][L] How does that look?
  10. So sometimes with mod_rewrites you are adding to a URL and other times you are removing from the URL? Had a noisy neighbor last night and I got a whopping 3 hours of sleep. Am ready to pass out, so not such a great time to learn mod_rewrites, but I appreciate your help nonetheless!! If I want to go from /client1/menu to /client1/menu.php then how about... RewriteCond ??????? RewriteRule client1/menu$ client1/menu.php [R=301][L] Can you explain your code? RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_URI} \.php($|\?) RewriteRule (.*)\.php$ $1 [L,R=301] The first line check if the request is not a file? Like /client/menu The second line checks what comes after the hostname and looks for a .php ending? What is ($|\?) The third line takes everything after the hostname and before a .php ending and strips off the .php ending?
  11. So if my mod_rewrite is correct, then why is it not working?? Please re-read my OP. The mod_write seems to be working in that the pretty URL www.mysite.com/client1/gallery/2019-holiday-party is being redirected to www.mysite.com/pnc/gallery/photo-gallery.php?gallery-id-2019-holiday-party HOWEVER the redirected "ugly" URL is appearing in the address bar.
  12. No, teacher, I am *adding* "menu.php" based on what you said before! 😉 Yes, in the "client1" directory, "menu.php" is like an index file. (I was going to use "index.php" a second time, but thought that might be confusing, so I opted for "menu.php".) So I want the "pretty" URL www.mydomain.com/client1/menu to map to the real URL www.mydomain.com/client1/menu.php
  13. So you should never use [R] since it is bad since it cause 3X redirects? Anywho, what about the crux of what I last wrote...
  14. I'm not sure... All I know is I have about a dozen complex mod_rewrite for another site I wrote that all work fine, and I tried to find ones similar to my needs for this photo site and modify them. I won't claim I truly understand mod_rewrites in and out, although I do like to learn. My understanding of things work is that you take a "pretty" URL like client1/gallery/2019-holiday-party and you rewrite it to something that Apache will recognixe like client1/gallery/photo-gallery.php?gallery-id=2019-holiday-party and then I *think* you tell Apache to redirect to that "real" URL but your browser still shows the "pretty" URL and then it is also a good idea to tell Apache you are done with [L]. How does that sounds?
  15. How so? RewriteCond %{REQUEST_URI} ^.*/menu\.php RewriteRule ^(.*)menu.php$ $1 [L,R=301] In the second line, (.*) would select everything after the hostname (e.g. "www.mysite.com") and before menu.pho And $1 would then contain that value above, minus the "menu.php" Okay, you got me there!
  16. To be honest, I am very rusty on mod_rewrites and was relying on old ones being done properly and hoping my tweaks would be enough to make these fit my new situation. I believe "R" is for "redirect" and "L" is for "last" as in don't run any more statements after this.
  17. I guess I should add that i have this file structure... public_html public_html > index.php public_html > client1 public_html > client1 > menu.php public_html > client1 > gallery public_html > client1 > gallery > photo-gallery.php public_html > client1 > gallery > 2019-holiday-party public_html > client1 > gallery > 2019-holiday-party > IMG_0001.jpg
  18. Getting my butt kicked today by Apache! 😠 When a user enters this URL... www.mydomain.com/client1/gallery/2019-holiday-party I want my mod_rewrite to go here... www.mydomain.com/client1/gallery/photo-gallery.php?gallery-id=2019-holiday-party Here is what I have... RewriteCond %{REQUEST_FILENAME} !-f RewriteRule client1/gallery/(.*)$ client1/gallery/photo-gallery.php?gallery-id=$1 [L,R=301] When I click on this hyperlink... <a href="/client1/gallery/2019-holiday-party">Holiday Party (2019)</a> ...my browser is going here... http://www.mydomain.com/client1/gallery/photo-gallery.php?gallery-id=2019-holiday-party When clicking on the above link, I do want to go to the above URL *location* but I want to see: http://www.mydomain.com/client1/gallery/2019-holiday-party in the browser Address Bar. The code above is simply a tweak from some earlier code that I wrote for another website that worked fine. What did I do wrong??
  19. Hello. I need help with a mod_rewrite that will take this URL... www.mydomain.com/client1/menu and load this URL... www.mydomain.com/client1/menu.php I tried this but it isn't working... RewriteCond %{REQUEST_URI} ^.*/menu\.php RewriteRule ^(.*)menu.php$ $1 [L,R=301] Thanks.
  20. Thanks @Psycho that is very helpful!! (Thanks to you too @requinix.)
  21. In my case, won't my array always match the order of the files in the directory and presumably be sorted alphabetically by file-name?
  22. When I have a break at work I'll look into that. Thanks for the tip!
  23. Okay, this I guess I knew... How would I apply the above to a simple - non Javascript control or whatever to make it so I have navigation tools? Here would be the scenario... - The user starts off in a photo gallery - which you guys helped me get working - and would see a bunch of thumbnails. - The user would click on a given thumbnail and be taken to a new page that uses a query-string to load the chosen thumbnail. And it would them load a larger version of said photo. - On that "details" page - which I will code today - I would like a simple way for the user to navigate forward/backwards one photo while staying on the "details" page, thus making the user experience better. ** brainstorming here ** Could I maybe accomplish navigation using what you mention above and hyperlinks? Or is this going to require me to reload the page since I am relying on server-side solutions? I'm at work right now, but trying to think of how I might be able to accomplish this "nice to have" feature. Thanks for your help! 🙂
  24. Hello. I have built a web page that is a gallery of pictures populated using an array. Now I would like to create a new web page that shows an enlarged version of a given thumbnail from the gallery. It would be nice once someone loads a photo on the details page if they could simply navigate forward/backwards one photo, instead of having to go back to the gallery to choose the next picture. Had I designed things using a database, then I know how to do this, but alas, this is a simple solution. Is there an easy way to leverage the array that I created - which contains a listing of all file-names from my photo directory - and somehow use HTML/PHP to navigate forward/backward one photo? Here is the array that I build containing all photos from my directory... <?php $path = "../WORKSPACE/images/"; $files = array(); // Check for Directory. if (is_dir($path)){ // Open Directory-Handle. $handle = opendir($path); if($handle){ // Iterate through Directory items. // Return name of next item in Directory (i.e. File or Folder). while(($file = readdir($handle)) !== FALSE){ if($file != '.' && $file != '..' && preg_match("#^[^\.].*$#", $file)){ // Not Directory, Not Hidden File // Add to array. $files[] = $file; // Simple array. } } closedir($handle); } } var_dump($files); exit(); ?> Thanks!
  25. Got it. My bad.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.