Jump to content

SaranacLake

Members
  • Posts

    648
  • Joined

  • Last visited

Posts posted by SaranacLake

  1.  

    6 minutes ago, kicken said:

    One option might be to ignore mod_rewrite and instead use DirectoryIndex.  Most people only use this to set an index file name for directories, but you can actually set it to a specific URL which will handle requests for directories.  That script can then grab the URL requested and handle it as needed.

     

    I could, but that just seems unnatural to me.

    What about the link above?

    https://stackoverflow.com/questions/21417263/htaccess-add-remove-trailing-slash-from-url

    Right below the RewriteEngine On line, add:

    To enforce a no-trailing-slash policy.

    	RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R] # <- for test, for prod use [L,R=301]
    	

     

    To enforce a trailing-slash policy:

    	RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*[^/])$ /$1/ [L,R] # <- for test, for prod use [L,R=301]
    	

     

    [EDIT: commented the R=301 parts because, as explained in a comment:

    Be careful with that R=301! Having it there makes many browsers cache the .htaccess-file indefinitely: It somehow becomes irreversible if you can't clear the browser-cache on all machines that opened it. When testing, better go with simple R or R=302

    After you've completed your tests, you can use R=301.

     

    That sounds like it has promise, although I'm not sure where to put the first block of code in my current .htaccess file with mod_rewrites??  :shrug:

  2. F*** ME!!!!

    I KNEW that the answer would be something stupid!!

    @kicken,

    You are indeed a "Guru" - and a gentleman - among men!!

     

    10 hours ago, kicken said:

    This tells me you have an actual directory named 2019-holiday-party inside your gallery folder.

    Right.  I have this structure...

    	public_html
    	     index.php
    	     client1/
    	          menu.php
    	          gallery/
    	               photo-gallery.php
    	               2019-holiday-party/
    	                    img_0001.jpg
    	                    img_0002.jpg
    	                    img_0003.jpg
    	               2019-diwali-festival/
    	                    img_0004.jpg
    	                    img_0005.jpg
    	               2019-company-picnic/
    	                    img_0006.jpg
    	

     

    The logic being that when you are on menu.php, you click on the link of the gallery you want to view, and that is a "pretty" URL like this...  "client1/gallery/2019-holiday-party" 

    That in turn launches /public_html/client1/gallery/photo-gallery.php which grabs the $_GET['gallery-id'] from the "pretty" URL

    And then this script finds a directory by that SAME NAME, and then it reads all of the photos in said directory, and displays them on the photo-gallery.php page!!

     

    Quote

    When I created a similar directory on my end then I get results similar to yours.

    The problem is mod_dir which in addition to handling DirectoryIndex files,

    I'm not sure exactly how it's interacting with your mod_rewrite rules, but it appears as though it triggers based on the original request url instead of the re-written URL.  When it issues the redirect however it still picks up the query-string that was added to the re-written URL.

     

    So, as a test, I pre-pended my photo directories with X_ and then tweaked my photo-gallery.php code like this...

    	$photoPath = "../gallery/X_$galleryID/";
    	

     

    When I do that, miraculously everything works, including a *proper* pretty URL and all of the photos from that directory being served up.

    But having to hack things like that is annoying at best...

     

    Quote

    This trailing slash behavior can be disabled by setting DirectorySlash Off in your configuration.  That should resolve the problem, though I'm not sure it's a good solution. 

     

    What I am trying to do here has to be extremely common from a programming standpoint?!

    Can you, or anyone else, think of a way to "have my cake and eat it too"?

    Like you, I am a little leery about setting DirectorySlash Off because I fear it could break the code for my separate e-commerce site which is very complex and nearing completion.

     

    Cannot believe that I just pissed away 4 days on this damn photo-gallery for work website.  What a waste of time, but THANK YOU (and @requinix ) for teaching me new things.

    If you can think of a way to have directories with the same names as my pretty URL that would be ideal...

    Thanks again!!    :thumb-up::thumb-up:

     

     

     

  3. @kicken

    Here you go...

    	This log file was created after running...
    	    curl -i http://local.mydomain/client1/gallery/2019-holiday-party
    	
    ************************
    127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (3) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] strip per-dir prefix: /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/client1/gallery/2019-holiday-party -> client1/gallery/2019-holiday-party
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (3) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] applying pattern '^(.*)index.php$' to uri 'client1/gallery/2019-holiday-party'
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (3) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] strip per-dir prefix: /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/client1/gallery/2019-holiday-party -> client1/gallery/2019-holiday-party
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (3) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] applying pattern '.*' to uri 'client1/gallery/2019-holiday-party'
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (4) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] RewriteCond: input='/Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/client1/gallery/2019-holiday-party' pattern='!-d' => not-matched
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (3) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] strip per-dir prefix: /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/client1/gallery/2019-holiday-party -> client1/gallery/2019-holiday-party
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (3) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] applying pattern 'client1/gallery/(.*)$' to uri 'client1/gallery/2019-holiday-party'
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (4) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] RewriteCond: input='/Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/client1/gallery/2019-holiday-party' pattern='!-f' => matched
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (2) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] rewrite 'client1/gallery/2019-holiday-party' -> 'client1/gallery/photo-gallery.php?gallery-id=2019-holiday-party'
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (3) split uri=client1/gallery/photo-gallery.php?gallery-id=2019-holiday-party -> uri=client1/gallery/photo-gallery.php, args=gallery-id=2019-holiday-party
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (3) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] add per-dir prefix: client1/gallery/photo-gallery.php -> /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/client1/gallery/photo-gallery.php
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (2) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] trying to replace prefix /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/ with /
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (4) add subst prefix: client1/gallery/photo-gallery.php -> /client1/gallery/photo-gallery.php
    	127.0.0.1 - - [04/Dec/2019:20:38:13 --0800] [local.mydomain/sid#7f80a305c320][rid#7f80a30b3aa0/initial] (1) [perdir /Users/user1/Documents/60-MYDOMAIN/10-INFORMATION_TECHNOLOGY/++htdocs/05-MyDomain/public_html/] internal redirect with /client1/gallery/photo-gallery.php [INTERNAL REDIRECT]
    	

  4. 7 minutes ago, kicken said:

    Then I guess you're stuck figuring it out on your own.  Without new info there's really nothing else to be said.  The rules you've posted work just fine for me on Apache 2.4.  Maybe there's an issue with 2.2 causing a difference, but I'm likewise not going to go through the hassle of setting up an Apache 2.2 environment to test.

    Your re-cap above has various errors in it, but I'm assuming they are just typos trying to transfer data to the post and not actual problems because otherwise Apache wouldn't start and you'd have no output.

    I fixed some type-o's?

    Should I try updating to a newer version of MAMP with Apache 2.4 if that is offered?

    So you want me to access the page using cURL and past a clean log here?

     

  5. 31 minutes ago, kicken said:

    You could post the log output.

    To keep it brief, the best thing to do would be to stop the server, make sure the log file is empty, start the server and run the CURL command to request your page.  That way the log file will only contain the details from that single request and be easier to follow.

     

    I know you are trying to help, but I'd sorta prefer not to do that since the log file contains sensitive info and it would be a pain to have to scrub it out.

    I feel like the answer is right in front of me, although I'm sure this thread has scared almost everyone else away.  ;-(

    Here is a recap of where I currently am...

    .htaccess

    	RewriteCond %{REQUEST_FILENAME} !-f
    	RewriteRule client1/gallery/(.*) client1/gallery/photo-gallery.php?gallery-id=$1 [L]
    	

     

    menu.php

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

     

    photo-gallery.php

    	echo '$_GET[gallery-id] = ' . $_GET['gallery-id'];
    	exit();
    	

     

    URLs:

       http://local.mydomain/client1/menu
        http://local.mydomain/client1/gallery/2019-holiday-party /?=2019-holiday-party

     

    Output

    Quote

    $_GET[gallery-id] = 2019-holiday-party/

     

     

     

    Notice that trailing backslash in RED that I have highlighted above!!!

     

    Final URL after rewrite:

    Quote

     

     

     

  6. I got logging to work for MAMP w Apache 2.2...

    	#Loglevel debug
    	RewriteLog "/Applications/MAMP/logs/rewrite2.log"
    	RewriteLevel 4
    	

     

    To be honest, the log file makes very little sense to me.  Seems like it is going over the same things in my htaccess file over and over again.  I don't see where it s appending on the mysterious /?gallery-id=2019-holiday-party

    I checked my mod_rewrite to make sure the last line of every block has an [L] so things don't bleed over.

    I still think this is a mod_rewrite issue or possibly something in the code of one of my files and not an Apache misconfiguration.

    Sure could use some help solving this very annoying issue!  :cry:

  7. CORRECTION:  The errors I posted above were from yesterday and probably related to dev errors.

    I do NOT see any error from today when MAMP was hanging up.

    So while the code @kicken didn't seem to work in my MAMP, nothing as such got logged.

    I say this is at the .htaccess level or coding level and not in Apache itself, but who knows?!

    :shrug:

  8. 10 minutes ago, kicken said:

    You'll have to do some troubleshooting then and figure out why.  I don't use a Mac, MAMP, or Apache 2.2 (2.4 is current).

    As far as I can tell looking at the Apache 2.2 docs that configuration should be valid.

    Check your error log, see if it says why it won't start.  Try starting it from a terminal window manually, see if that shows anything.  Try a syntax check on the config file.

    I am looking in the log now and I see lots of errors but the wrap and its hard to make heads or tails.

     

    See lots of "File does not exist" and <path>/public_html/gallery

    Also some [error][client 127.0.0.1]Directory index forbidden by Options directive: <path>/public_html/pnc/

     

    I guess that is when things wouldn't start up?

     

    If I comment out the lines you gae me, MAMP and my scripts run okay except the URL is not right - as always - and as I last posted that messes up my $_GET which isn't life-ending, but still.

    I just don't understand why a simple rewrite is causing all of these issues...  *sigh*

  9. Interesting side-note...

    In photo-gallery.php, I added...

    	echo '$_GET[gallery-id] = ' . $_GET['gallery-id'];
    	

    and when I run things I get...

    	$_GET[gallery-id] = 2019-holiday-party/
    	

     

    The point?  It is that my pretty URL is getting messed up for reasons still unknown, and the garbage being added onto my pretty URL (i.e. "/?gallery-id=2019-holiday-party") is breaking my code when I run things in that the $_GET value is not what I am expecting.

     

  10. 7 minutes ago, kicken said:

    It would appear MAMP is using an outdated version of Apache.  Try this instead.

    
    <VirtulHost *:80>
        DocumentRoot "some path"
        ServerName local.mydomain
        LogLevel debug
        RewriteLog "/Applications/MAMP/logs/rewrite.log"
        RewriteLogLevel 6
    </VirtualHost>
    

     

    Made the change.

    Quit MAMP.

    Started it up.

    Apache Server will not start.

    The phpinfo page says I have Apache/2.2.34

     

     

  11. 12 minutes ago, kicken said:

    Replace (or comment out) your current LogLevel in the virtual host.

    
    <VirtulHost *:80>
        DocumentRoot "some path"
        ServerName local.mydomain
        #LogLevel debug
        LogLevel rewrite:trace6
    </VirtualHost>

    Whenever you get things working, switch it back to what you had before or your log will get big fast.

     

    That command breaks my webserver and it won't now start.

     

     

  12. 5 minutes ago, kicken said:

    Neither of the LogLevel directives you show are what I posted.

    
    LogLevel rewrite:trace6

    You need to have the correct setting to get any log output.

    When changing the httpd.conf you need to stop and start the server for the change to take effect.

    Where do I put your line of code in the httpd.conf file?

    And do I add that in addition to the lines I found above?

  13. 38 minutes ago, kicken said:

    Is your photo-gallery.php script possibly issuing a redirect?

    Only for the access-denied.php and page-not-found.php

     

    38 minutes ago, kicken said:

    If you edit your main httpd.conf file instead of a .htaccess file, you can enable rewrite trace logging.

    
    LogLevel rewrite:trace6

    This will generate step-by-step logs in your server's ErrorLog file showing how your rules are processed.   You'd get a bunch of entries that look something like this:

     

     

    This is getting really complicated...  ;-(

    I am running MAMP.

    Went to Applications : MAMP : conf : apache : httpd.conf

     

    Searched for "LogLevel"

    I see...

    	LogLevel error
    	

     

    In my virtual host I added...

    	<VirtulHost *:80>
    	    DocumentRoot "some path"
    	    ServerName local.mydomain
    	    LogLevel debug
    	</VirtualHost>
    	

     

    Do I have to reboot my Mac?

    I shut down MAMP, started it up, ran my web page, and in...

    "/Applications/MAMP/logs/pache_error.log"

     

    ...I don't see anything of value at today's time and date.

     

    Did I do that right?

     

    And why is the mod_rewrite turning int hell?

     

  14. 31 minutes ago, kicken said:

    Perhaps you should just post your whole re-write configuration.  Make sure you don't have extra configuration directives in other areas that might cause the problem (httpd.conf, .htaccess files)

    Here you go...

    	RewriteEngine on
    	# Addresses issues with how Apache handles mod_rewrites!!
    RewriteBase /
    	
    # REWRITE INDEX.PHP TO ROOT
    #-------------------------------------------------------------------------------
    #PRETTY:    www.mydomain.com/
    #UGLY:        www.mydomain.com/index.php
    	RewriteCond %{REQUEST_URI} ^.*/index\.php 
    RewriteRule ^(.*)index.php$ $1 [L,R=301]
    	
    # SECURITY
    #-------------------------------------------------------------------------------
    #Prevent Directory Listings
    Options -Indexes
    	
    # ERROR PAGES
    #-------------------------------------------------------------------------------
    #Handle Access-Denied.
    ErrorDocument 403 "/utilities/access-denied.php"
    	#Handle Page-Not-Found.
    ErrorDocument 404 "/utilities/page-not-found.php"
    	
    # CLIENT HOME
    #-------------------------------------------------------------------------------
    #PRETTY:    client1/menu
    #UGLY:        client1/menu.php
    	#Rewrite only if the request is not pointing to a real file.
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule .* $0.php [L]
    	
    # PHOTO-GALLERY
    #-------------------------------------------------------------------------------
    #PRETTY:    client1/gallery/2019-holiday-party
    #UGLY:        client1/gallery/photo-gallery.php?gallery-id=2019-holiday-party
    	#Rewrite only if the request is not pointing to a real file.
    RewriteCond %{REQUEST_FILENAME} !-f
    	RewriteRule client1/gallery/(.*)$ client1/gallery/photo-gallery.php?gallery-id=$1 [L]
    	

  15. 1 hour ago, kicken said:

    Then the most likely explanation is that ?gallery-id=2019-holday-party bit is there from the beginning of the request (ie, you're linking incorrectly).

    I find when testing rewrites the best thing to do is ignore the browser and instead using something like curl or wget to request the pretty url and see what the response is. 

    
    curl -i http://example.com/client1/gallery/2019-holiday-party

    Get yourself a copy of CURL and run the above command and see what it says (post it here if you're unsure what the output means).

     

    In Terminal I ran:

    	curl -i http://local.mydomain/client1/gallery/2019-holiday-party
    	

     

    I got these results...

    	HTTP/1.1 301 Moved Permanently
    Date: Wed, 04 Dec 2019 21:29:01 GMT
    Server: Apache/2.2.34 (Unix) mod_wsgi/3.5 Python/2.7.13 PHP/7.2.10 mod_ssl/2.2.34 OpenSSL/1.0.2o DAV/2 mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_perl/2.0.9 Perl/v5.24.0
    Location: http://local.mydomain/client1/gallery/2019-holiday-party/?gallery-id=2019-holiday-party
    Content-Length: 297
    Content-Type: text/html; charset=iso-8859-1
    	<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>301 Moved Permanently</title>
    </head><body>
    <h1>Moved Permanently</h1>
    <p>The document has moved <a href="http://local.mydomain/client1/gallery/2019-holiday-party/?gallery-id=2019-holiday-party">here</a>.</p>
    </body></html>
    	

     

    I have no switches (??) after my RewriteRule...

     

    So WTF?

     

  16. I formatted/highlighted what you said so it is clear...

     

    10 minutes ago, kicken said:

    Scenario #1: mod_rewrite *without* an [R]

    It means the server doesn't notify the browser that the URL has been changed.   The server just handles the request using the new URL and returns the result and the browser is non the wiser.  As a result, the browser just shows the original unchanged ("pretty") URL.

     

    10 minutes ago, kicken said:

    Scenario #2: mod_rewrite with [R]

    It means the server will send a response back to the browser telling it that the URL has changed and it needs to re-request using the new URL.  As a result the browser updates it's address bar (with the ugly URL) and re-requests the new URL.

     

     

    10 minutes ago, kicken said:

    Then the most likely explanation is that ?gallery-id=2019-holday-party bit is there from the beginning of the request (ie, you're linking incorrectly).

    I find when testing rewrites the best thing to do is ignore the browser and instead using something like curl or wget to request the pretty url and see what the response is. 

    
    curl -i http://example.com/client1/gallery/2019-holiday-party

    Get yourself a copy of CURL and run the above command and see what it says (post it here if you're unsure what the output means).

    Hopefully installing cURL on a Mac is fairly idiot proof?

    Hopefully using cURL is as simple as pasting your above command into cURL?

     

     

    10 minutes ago, kicken said:

    It does, in a way, by telling the search engine that "The URL you requested (X) has changed to the url (Y) forever, so don't request it again".  Your browser can understand that request as well, it's not a search-engine specific request.

     

    Don't request WHAT again?  The pretty URL?

    If so, then what is the benefit to search engines and to your website as far as SEO?

     

    I will try to get cURL installed between final daily meetings and get back to you ASAP.

     

    And THANKS for helping me to slowly get what [R] does...  😉

     

    Any comments on when and why to use [L] ??

     

  17. 2 hours ago, kicken said:

    Also, in case you're still not clear on the [R] issue: A normal RewriteRule without the [R] tells Apache "Hey buddy, I know the client asked for X but let's really give them Y instead, don't tell them about it though."

    What does "don't tell anybody though" mean?

    So if I remove the [R], then are you implying that in the address bar is the pretty URL, and the browser serves up the ugly URL (which is the web page) but the address retains the pretty URL??

     

     

    Quote

    If you add the [R], that changes the hypothetical conversation to "Hey buddy, I know the client asked for X but they really want to ask for Y.  Can you please let them know they need to request Y instead?"

    What does, "Can you please let them know they need to request Y" mean?

    What would I see in the browser and address bar?

    In the address bar is the pretty URL.  The browser presumably uses the ugly URL to serve up the web page, right?

    What happens to the pretty URL in the address bar when you have [R] ??

     

     

    Quote

    By adding the 301 into the mix ([R=301]), your modifying the conversation even further to say "Hey buddy, I know the client asked for X but they really want to ask for Y.  Can you please let them know they need to request Y instead and that this will always be the case and they should never request X again?"

    Browsers may cache such 301 redirects so that if you attempt to visit the original URL again the browser itself will re-write to the redirected URL before even making the request.  As such, if you make such a redirect by mistake (as you were) it's not easily fixed.  Sometimes closing the browser entirely (not just the tab/window) will clear those redirects, other times you may  have to clear the browsers cache to remove them.

     

    Sorry, but a little unsure of what this means...

    In the address bar is the pretty URL.  The browser presumably uses the ugly URL to serve up the web page, right?

    What happens to the pretty URL in the address bar when you have [R=301] ??

     

    My understanding of R=301 was that it just told search engines that the pretty URL was really the ugly URL.

    Guess I don't understand that correctly...

     

  18. 1 minute ago, kicken said:

    They are related because these control what mod_rewrite does after it's re-written the URL.

    As has been said multiple times, [R] causes mod-rewrite to instruct the client to re-direct to the new URL.

    [L] causes mod-rewrite to stop processing any further re-write rules.

    You've been told to remove [R], but keep [L], yet you keep removing both.

    I tried just [L] and that does NOT fix things....

    I thought I mentioned that above?

    So since just having [L] does not work, that is why I said I don't follow the whole L/R thing...

     

  19. @kicken,

    Thanks for the response.  Am at work and getting ready for a meeting, but let me try and get my head back into this quickly...

     

    1 hour ago, kicken said:

    That link is relative to the current URL.  So if you're say on https://example.com/client1/menu, clicking that link will attempt to load https://example.com/client1/menu/client1/gallery

    When you're rewriting your URLs you need to take into account your URLs may not match up with what your filesystem looks like and make sure you link accordingly.  In general it's almost always best to link things in a domain relative fashion, with a leading /.

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

     

    Let say that I am on menu.php and I cick on one of the pictures/links to choose a gallery...

    The location of menu.php is: public_html/client1/menu.php

    The URL for menu.php is: http://local.mydomain/client1/menu

    And in menu.php I have this HTML code...

    	<!-- MENU -->
    	<a href="/client1/gallery/2019-holiday-party">Holiday Party (2019)</a>
    	<a href="">other gallery links to follow</a>
    	

    So I believe I was using an absolute reference like you suggest.

    When I click on that first link, I want it to launch the gallery for the "Holiday Party (2019)".

    In my mod_rewrite, I have this to allow a pretty URL when requesting the gallery:

    	RewriteCond %{REQUEST_FILENAME} !-f
    	RewriteRule client1/gallery/(.*)$ client1/gallery/photo-gallery.php?gallery-id=$1 [L,R=301]
    	

     

    So the pretty URL from the hyperlink above should yield: http://local.mydomain/client1/gallery/2019-holiday-party

    And this should map to (and serve up) the ugly URL: http://local.mydomain/client1/gallery/photo-gallery.php?gallery-id=2019-holiday-party

     

    HOWEVER, as I mentioned a couple times above to @requinix...

    Scenario #1:

    If I have [L,R=301] in my mod_rewrite then I get...

    http://local.mydomain/client1/gallery/photo-gallery.php?galery-id=2019-holiday-party

    (That is the correct end location/file/query string, BUT it is the ugly URL which I clearly do NOT want!!)

     

    Scenario #2:

    If I remove [L,R=301] in my mod_rewrite then I get...

    http://local.mydomain/client1/gallery/2019-holiday-party/?gallery-id=2019-holiday-party

    (The first part of the URL is what the pretty URL should be, but then there s oher junk on the end that is wrong?!)

     

    So how do I fix this? 

    I'm not sure if @requinix saw these *subtle* differences or understood why I'm not getting what I want.

    And I'm sorry, but I don't see how [L] or [R] or [R=301] or [L,R=301] is related.

     

     

  20. 15 minutes ago, requinix said:

    o rly?

    Oh really?

    Yes.

    I don't know as much as you, but I can say with certainty that my links need to be "fully formed" and have all 3 components:

    client1 directory

    gallery directory

    2019-holiday-party which is an argument passed to the $galleryID parameter/variable in my code used to serve up the apropriate gallery.

     

  21. 1 minute ago, requinix said:

    I'm tired.

    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule client1/gallery/(.*)$ client1/gallery/photo-gallery.php?gallery-id=$1 [L,R=301]

    That was your original code. Remove the [R] flag and only the [R] flag.

    Then make your link look like what I put in my last post.

     

    Removed: R=301

    Changed link to: <a href="client1/gallery/">

     

    ===> Page Not Found

     

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