creating nice url but not with slashes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mikek12004
    New Member
    • Sep 2008
    • 200

    creating nice url but not with slashes

    Almost for all thing I use my index.php with the value of 'page' as a criterion. However when I view my products which is something like this
    www.mysite.com/index.php?page= 2&kwd=1.0096&de scription=Love to give&type=album
    to be viewed
    www.mysite.com+ album+1.0096+Lo ve to give

    note that I do not have a problem with the slashes as seperators but then I have to change all the src's attributes of the images and I have read somewhere that woth anything else like '+' or ':' as a separator will work, is it true (in a working example with slashes tried to replace them in the .htaccess file with + and got object not found both when I commented the + and when not);
    the is also the point of having in my description spaces, in an example of two with multiwork get worked ok, but read somewhere I have to pass them through urlencode() or something like that, is it necessery and changes this anything in the .htaccess file?
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    The plus symbol in a htaccess statement means one or more of the preceding character/range. So you need to escape the symbol. I haven't ever tried to have + in my urls, so give it a go, but I suspect that's why it's not working. I hope that a simple "\" character will be enough, but you might have to play around with a {QUERY_STRING} condition??

    Comment

    • mikek12004
      New Member
      • Sep 2008
      • 200

      #3
      tried but not working, anyone could give an example?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by mikek12004
        www.mysite.com+ album+1.0096+Lo ve to give
        this doesn’t look like a good choice, since all seems to be part of the domain and I’m not sure, whether this has a query string at all…

        Code:
        www.mysite.com/album+1.0096+Love to give
        at least should give you a query string to operate on

        Comment

        • mikek12004
          New Member
          • Sep 2008
          • 200

          #5
          Didn't quite understand what you said, regardless the original url is
          https://www.mysite.com/index.php?pag...scription=Love to give&type=album
          and want to modify to nice url so that the user can type
          www.mysite.com/album/Love to give
          however with slashes as seperator since I have given relative directories to the images (which would be good to keep them aftear all I use a demo folder all the time) they get broken up, so read somewhere to use some other symbol as the + or : ,that is the one thing. The other was my consern about the description variable having symbols like space, question marks etc. will it be a problem and if so how to handle it?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            Originally posted by mikek12004
            The other was my consern about the description variable having symbols like space, question marks etc. will it be a problem and if so how to handle it?
            usually a browser escapes invalid characters before sending the request. (? is a valid character, see RFC 1738 for more info)

            Comment

            • mikek12004
              New Member
              • Sep 2008
              • 200

              #7
              and about the issues with the slashes? Would you used it even if it screws your relative directory in the images or would you use some other symbol (+, - , : etc. )?

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                what issue? if mod_rewrite works as expected, the server is not requested of invalid directories.

                Comment

                • mikek12004
                  New Member
                  • Sep 2008
                  • 200

                  #9
                  suppose we have an www.aaa.com/index.php?id=1&user=mike which has an image with src='img/a1.jpg'
                  when I used htmod so that that url works www.aaa.com/1/mike the image appeared broken, read somewhere that this is because of the URL being like this and a possible solution if I didn't want to use absolute paths would be to replace the '/' with another symbol. Tried the www.aaa.com/1+mike
                  (with the '+' escaped and not) in the rewrite rule but always got 'not found' when return to the slashes the htaccess worked fine

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    Originally posted by mikek12004
                    when I used htmod so that that url works www.aaa.com/1/mike the image appeared broken,
                    then you need an additional filter for the image urls.

                    the rule I use…
                    Code:
                    	# remove the fake directories for internal files (CSS, JS)
                    	RewriteRule ^\w+/(.+)$ $1 [NC]

                    Comment

                    • mikek12004
                      New Member
                      • Sep 2008
                      • 200

                      #11
                      So in my htaccess would look like this
                      Code:
                      RewriteEngine On # Turn on the rewriting engine
                      # Handle product requests 
                          RewriteRule ^products/([0-9]+)/?$ index.php?id=$1 [L] 
                      # remove the fake directories for internal files (CSS, JS) 
                          RewriteRule ^\w+/(.+)$ $1 [NC]
                      right?

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        not sure if it works for you, since you have to go 2 directories back (I use more than one such line and our cases may not be compareable). you could even make it more specific to images…

                        Comment

                        • mikek12004
                          New Member
                          • Sep 2008
                          • 200

                          #13
                          would the 2 levels back be
                          Code:
                          # remove the fake directories for internal files (CSS, JS)  
                              RewriteRule ^\w+/(.+)/(.+)/$ $1 [NC]
                          'cause right now even with the original I do not see the picture going back one level
                          I realise that I would face the same issue with the CSS/JS also so a rule which could make them work OK is much desirable.
                          Your method works ok even if you use the normal url and not the nice one?

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #14
                            you’re going down 3 directories which, if I remember right, does not match your URL.
                            Originally posted by mikek12004
                            Your method works ok even if you use the normal url and not the nice one?
                            hard to tell, I normally use a separate domain for images, CSS and Javascript (but what’s relative defined, works)

                            Comment

                            • mikek12004
                              New Member
                              • Sep 2008
                              • 200

                              #15
                              Just to get the hang of I have an index.php which has this:
                              <?php
                              echo $id=$_GET['id'];

                              echo 'none';
                              ?>
                              <img src="imgs/bemember.jpg" />
                              and the htaccess file
                              RewriteEngine On # Turn on the rewriting engine
                              # Handle product requests
                              RewriteRule ^products/([0-9]+)/([0-9]+)/?$ index.php?id=$1 &b=$2
                              RewriteRule ^\w+/(.+)/(.+)/(.+)/$ $1 [NC]
                              now whether I use

                              or

                              I get redirected to the correct page but the image (when I choose right click+propertie s) regardless the rule shows

                              how would you make it in this situation?

                              Comment

                              Working...