Jump to content

SaranacLake

Members
  • Posts

    648
  • Joined

  • Last visited

Posts posted by SaranacLake

  1. 10 minutes ago, requinix said:

    Think of another .php file you have on the site. Pick any one. Do you want to be able to access that one without the .php extension too?

    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. 2 minutes ago, requinix said:

    Do not put the gallery-id thing into your links.

    
    <a href="/client1/gallery/2019-holiday-party">

     

    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?!  :shrug:

  3. 16 minutes ago, requinix said:

    Okay. But do you want to support other .php files?

    I will not ask a fourth time.

    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. 16 minutes ago, requinix said:

    Let me summarize what we covered in the first few posts:

    1. The URL in the address bar is changing
    2. [R] tells mod_rewrite that it should tell Apache that it should tell the browser to redirect to the new URL
    3. You have a [R] in that rule

    I can't make it any more clear than that without actually giving away the answer.

     

    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. 16 minutes ago, requinix said:

    Depends on the answer to the "do you want to support other .php files" question I asked earlier.

     

    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. 12 minutes ago, requinix said:

    I don't understand how you could possibly be confused about what the URL is.

    Your browser seems to be remembering the redirect. Try an incognito/private window, or clear your cache.

    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. 33 minutes ago, requinix said:

    I never said it was correct. I said your understanding of how the process works was correct - at least up to the part about redirecting. I then corrected you on how it works when you do and don't include the [R].

    So you should now understand why what you have is not working the way you want, and what you need to do to fix it.

    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!

     

    It's not bad. It just isn't what you want to do.

    At least in this thread. In your other thread, you do want the [R] on that menu.php rule because you want the user to see the /whatever/ URL. I assume.

    In my first thread, I want to go from /client/menu to /client/menu.php so I am adding to things, and you are saying I do want a redirect here because I want to go to the script menu.php?

    Correct?

     

    Then in this thread, I want to go from /client1/gallery/2019-holiday-party to /client1/gallery/photo-gallery.php?gallery-id=2019-holiday-party where here I am not adding or deleting but creating a new URL, and here I would also think I want to redirect to the script "photo-gallery.php", right???

    You make it sound like my use of [L,R=301] is breaking things?  Is that true?  And if so, please help me udnerstand what I need to do to fix things!

    Again, my this 2nd mod_rewrite is sending me to the correct ugly URL and script, but I do NOT want to see the ugly script when the browser redirects to "photo-gallery.php".  INSTEAD, I want the user to still see the pretty URL.

    So how do I make that happen?

     

  9. 8 minutes ago, requinix said:

    Not this time 😁 This specific rule really is about removing the "menu.php". The other rule (which you haven't shown) is about adding it.

    So sometimes with mod_rewrites you are adding to a URL and other times you are removing from the URL?

     

     

    8 minutes ago, requinix said:

    For adding extensions you need two rules: obviously the one to add the extension, but you should have another rule to remove it if someone tries to go to /menu.php because of SEO stuff.

    Here is the second one because it's a little more interesting. Try coming up with the first one yourself.

    
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{REQUEST_URI} \.php($|\?)
    RewriteRule (.*)\.php$ $1 [L,R=301]

     

    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?

  10. 3 minutes ago, requinix said:

    It's not bad. It just isn't what you want to do.

    At least in this thread. In your other thread, you do want the [R] on that menu.php rule because you want the user to see the /whatever/ URL. I assume.

    The rest of the stuff you said was right.

     

    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.

  11. 1 minute ago, requinix said:

    Oh, yeah, sorry I kinda glossed over it: you're removing /menu.php entirely.

    No, teacher, I am *adding* "menu.php" based on what you said before!  😉

     

    1 minute ago, requinix said:

    Presumably you have menu.php as an index, or have set up another rewrite so that /whatever/ is mapped to /whatever/menu.php.

    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

     

     

  12. 2 minutes ago, requinix said:

    Not quite. mod_rewrite will rewrite and "tell" Apache about the new one automatically. That's its whole point. Base functionality. You don't need [R] to do that.

    What [R] means is "figure out the new URL and send it to the client with a 3xx redirect".

    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...

    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

    Do you agree with everything before the redirect part?

     

  13. 4 minutes ago, requinix said:

    Right so far.

    So if [R] means redirect...

    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?

     

  14. 18 minutes ago, requinix said:

    You've written a rule that will turn /menu.php into /menu.php.

    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"

     

    18 minutes ago, requinix said:

    People think of this stuff backwards. You are not removing the .php extension. You are adding it. As in you want someone to see /menu in their browser and have the server add the .php extension.

     

    Okay, you got me there!

     

  15. 12 minutes ago, requinix said:

    Do you know what the [R] flag to RewriteRule means?

    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.

  16. 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
    	

  17. 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?? 

     

  18. 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.

     

  19. 1 hour ago, requinix said:

    Another option besides passing the number is to make sure the file list is always sorted (however, just always sorted), then you can search for the filename in it to get the 'n' index.

    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?

  20. 21 minutes ago, Barand said:

    Some complex maths is required.

    The array has an index, so if you are currently on the Nth element, subtract 1 to get the previous item or add 1 to get the next

    
    $current = $files[$n];
    $previous = $files[$n-1];
    $next = $files[$n+1];

     

    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!  🙂

     

  21. 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!

     

     

×
×
  • 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.