We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32046
    • 75 Posts
    Hi Evangard,
    Thanks for adding that option. Is the plugin for Revo or Evo?
      • 32046
      • 75 Posts
      Hi Evangard,

      Looking deeper into this solution and it is an excellent idea. Man, every time I think modX can’t do something it turns around and kicks my ass again. Plugins rock!

      I would still prefer the .htaccess method in this case as two "simple" lines "should" solve the issue for me, but if I cant get it to work that way (and I’m learning .htaccess can be a fickle b*tch") then I know I’ve got a great alternative here. Regardless, I want to use this method in the future anyway as it is so damn flexible, the more I consider it the better it seems to get.

      I gather the plugin is written for Revo? Would that be Evo compatable and if not can you advise the points of difference?
        • 36764 ☆ A M B ☆
        • 45 Posts
        Evengard aka Eiventeleiron Reply #13, 15 years, 4 months ago
        It is for Revo, haven’t worked with Evo, so can’t give advice, but it would need some parts rewritten because of API changes.
          • 9102 ☆ A M B ☆
          • 318 Posts
          Evengard, that’s a cool snippet, looks like it basically figures out what the URL needs to be rewritten to and sends a modx forward. Interesting approach.

          The thing is, the .htaccess method should work. Something must be wrong with the code I posted -- I didn’t test it as-is, which is always a mistake.

          Here is the exact code in the relevant section of my .htaccess, which is working live right now on freenaturepictures.com:

          #SEO-friendly pagination
          RewriteRule ^(.*)-pictures-1\.php$ $1-pictures.php [R=301,L]
          RewriteRule ^(.*)-pictures-([0-9]+)\.php$ $1-pictures.php?page=$2 [L,QSA]
          
          # For Friendly URLs
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
          


          That first redirect is just to take care of the duplication of page 1, you shouldn’t need it. Obviously I’m using an extension of .php for HTML docs, you should use whatever your HTML extension is.
            • 9102 ☆ A M B ☆
            • 318 Posts
            I think maybe the difficulty is that you’ve separated your conditions from the friendly URL rule. They should be directly above it in order to apply.
              • 9102 ☆ A M B ☆
              • 318 Posts
              OK, I tested on my dev subdomain, and got it working. .htaccess is very picky, you have to have everything including whitespace exactly right. This works for me:

              RewriteRule ^productId\/([0-9]+)$ rose-pictures.php?page=$1 [L,QSA]
              
              # For Friendly URLs
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
              


              I currently have this code working on my dev subdomain, it shows the page rose-pictures.php?page=2 when you request productId/2. I can’t get it to work right without including the file extension, so you might want to do that. Presumably yours is .html.

              I suggest you try the following exact code for your .htaccess, let me know how it works:
              Options +FollowSymlinks
              RewriteEngine On
              RewriteBase /
              
              # Fix Apache internal dummy connections from breaking [(site_url)] cache
              RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
              RewriteRule .* - [F,L]
              
              # Exclude /assets and /manager directories and images from rewrite rules
              RewriteRule ^(manager|assets)/*$ - [L]
              RewriteRule \.(jpg|jpeg|png|gif|ico)$ - [L]
              
              # For friendly product URLs
              RewriteRule ^productId\/([0-9]+)$ /product.html?pid=$1 [L,QSA]
              
              # For Friendly URLs
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
              


              Edit: just realized you’re using Evo. There might be one difference, I’m not sure if Evo passes query strings properly through the friendly URL redirect the way Revo does. You might try product.html&pid=$1 instead. That works for me in Revo too, and it should work in Evo. The idea is you’re appending another parameter to the request that already has the parameter q=product.html
                • 9102 ☆ A M B ☆
                • 318 Posts
                OK, here’s a fun irony for you -- I was completely wrong about the problem in the first place. There was nothing wrong with your original redirect except that it was in the wrong place, and possibly that you left out the file extension. The following also works fine for me:

                # For friendly product URLs
                RewriteRule ^productId\/([0-9]+)$ /index.php?q=rose-pictures.php&page=$1 [L,QSA]
                
                # For Friendly URLs
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^(.*)$ /index.php?q=$1 [L,QSA]
                
                  • 32046
                  • 75 Posts
                  Hi esnyder,
                  Dude, thanks for all the time you’ve put into this, it’s just awesome smiley. I’m travelling today but hope to attack this again tomorrow. I really would prefer an .htaccess solution over evengards wicked plugin (the idea of which I’m definitely stashing away for later use, man modX just rocks, the things you can do in modX blow my mind!), so I’ll have a stab with your suggested alterations and let you know the result.

                  Can you explain why the order of the statements makes a difference here, I just can’t see how it should affect it?

                  Funny, I always hated mod-rewrite and avoided it like the plague, now I’m actually wanting to explorer it (and maybe one day even conquer it wink hah!). Cheers dude.
                    • 9102 ☆ A M B ☆
                    • 318 Posts
                    I think RewriteCond statements only apply to the RewriteRule directly below them. It sort of creates a conditional block that only executes when the conditions are fulfilled. It would be really nice if the syntax supported enclosing the block in curly braces or something, but it doesn’t. I’m not completely certain how this works, honestly, but all of the working .htaccess code that I’ve seen or used has RewriteRule statements directly below the RewriteCond statements with no extra line breaks.

                    Anyway, I get an internal server error when I put the statements in the order you had them, but it works fine if you put the first rewrite above the conditions and leave the friendly URL rewrite directly below them.

                    I’ve brought my entire site down by having an extra space character in .htaccess in the wrong place. It’s very picky.

                    Edit: and you’re welcome, it wasn’t that much trouble. SEO in MODx is kind of my specialty, so if there’s somthing related to it I like to make sure I understand what’s going on.
                      • 32678
                      • 290 Posts
                      Quote from: esnyder at Jun 07, 2011, 01:23 PM
                      SEO in MODx is kind of my specialty, so if there's somthing related to it I like to make sure I understand what's going on.

                      freejung, you would be my hero if you were able to help me with a FURL issue I'm trying to solve with htaccess. I've applied several approaches found here and elsewhere--some do nothing while others create a 500 error. I'm a relative htaccess neophyte, so...

                      My needs are simple (I believe).

                      First, I have a site / FURL structure like:

                      www.mysite.com/container/cat1/resource.html
                      www.mysite.com/container/cat2/resource.html
                      etc.

                      I want to accomplish the FURL:

                      www.mysite.com/container/resource.html

                      Any ideas on how to do this with htaccess?

                      In addition, I've tried to add rules to help with canonicals; currently my homepage redirects with 404 with...
                      www.mysite.com/index
                      www.mysite.com/index.html

                      This all results from a migration I handled poorly. I'm going to have to add dozens of additional redirects because of a new site structure, and a migration of blog content from Wordpress to MODX. So, with this said, any guidance on how to successfully redirect...

                      www.mysite.com/old-blog-index/ to www.mysite.com/new-blog-index

                      OR

                      www.mysite.com/blog/old-post-URI.html to www.mysite.com/new-blog-index/new-post-URI.html

                      ...would be supremely appreciated.

                      One more question. All site URLs are .html. Meaning, www.mysite.com/../resource.html.

                      I have canonicals set as
                      [[!++site_url]][[*alias]]
                      and they appear in the head like: www.mysite.com/resource (without '.html').

                      I prefer the latter, so is there a system setting I'm missing?

                      The site I've migrated was on Evo; I'm now on Revo 2.2.10 and had none of these issues with Evo...

                      Thanks in advance -- any input you provide is greatly appreciated.

                      Here's the full htaccess (mysite=my actual domain):

                      RewriteEngine On
                      RewriteBase /
                      
                      # Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
                      #RewriteCond %{HTTP_HOST} .
                      #RewriteCond %{HTTP_HOST} !^mysite\.com [NC]
                      #RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
                      #
                      # or for the opposite domain.com -> www.domain.com use the following
                      # DO NOT USE BOTH
                      #
                      #RewriteCond %{HTTP_HOST} .
                      #RewriteCond %{HTTP_HOST} !^www\.example-domain-please-change\.com [NC]
                      #RewriteRule (.*) http://www.example-domain-please-change.com/$1 [R=301,L]
                      
                      
                      # The Friendly URLs part
                      RewriteCond %{REQUEST_FILENAME} !-f
                      RewriteCond %{REQUEST_FILENAME} !-d
                      RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]
                      
                      # The following directives stop screen flicker in IE on CSS rollovers. If
                      # needed, un-comment the following rules. When they're in place, you may have
                      # to do a force-refresh in order to see changes in your designs.
                      
                      #ExpiresActive On
                      #ExpiresByType image/gif A2592000
                      #ExpiresByType image/jpeg A2592000
                      #ExpiresByType image/png A2592000
                      #BrowserMatch "MSIE" brokenvary=1
                      #BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
                      #BrowserMatch "Opera" !brokenvary
                      #SetEnvIf brokenvary 1 force-no-vary