We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24278
    • 165 Posts
    Currently my URIs look like this http://www.domain.tld/folder_name/filename_name.html (where the .html is suffixed to the alias).

    I would like to remove the .html from the URIs. But, since the pages are indexed by search engines and have been linked by others I would not like to lose those referrals. I would like to redirect (with 301) all requests for http://www.domain.tld/folder_name/filename_name.html to http://www.domain.tld/folder_name/filename_name

    Is the above possible with .htaccess directives or is there some other way to do this? I am fairly new with the server side and have no clue (just guessing) grin

    Hope I have been able to clearly state my problem. FYI, I am hosted on linux.
      • 24278
      • 165 Posts
      is there a possibility of my requirement being fulfilled with either htaccess directive or any other method. Or, will I lose all the backlinks once I remove the .html form the URIs.
      thanks raavi.
        • 4626
        • 57 Posts
        You should be able to do it with htaccess, but I’m not quite sure how – it’s been a while since I last wrote my own htaccess-files...

        Something like this might work though. Add this line to your .htaccess-file:
        RewriteRule ^(.*).html$ $1 [R,L]
        

        between these two lines:
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
        

        So the result looks like:
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*).html$ $1 [R,L]
        RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
        
          • 24278
          • 165 Posts
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*).html$ http://domain/$1 [R,L]
          RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


          I tried the code above and it seems to redirect (with one small modification, where I added RewriteRule ^(.*).html$ http://domain/$1 [R,L]).

          But now I do not seen any styles nor do I see any images. Any ideas why this is happening.
            • 4626
            • 57 Posts
            I’m sorry I don’t why you don’t see any styles or images... Are you developing the site on your own server? Can you access the rewrite_log?

            You may have to change the rule I gave you so that you escape the ".". Your new rule would be:
            RewriteRule ^(.*)\.html$ http://domain/$1 [R,L]


            Maybe that would help a little... Could you also check what the generated BaseHref is for your pages?
              • 24278
              • 165 Posts
              Carl, thank you for your time and effort.

              I am developing the site on my winxp home edition desktop with XAMPP.

              I used the new rule, but the effect is the same as earlier. I still cant see styles nor images.

              The basehref is generated correctly, as http://domain/

              Also, when I tried to access the manager (like I always do) with http://domain/manager/ it gives me the MODx 404 page (without styles and images) and the url looks like this... http://ap/manager/?q=manager

              All this is so confusing grin Hope you can help solve this issue. Awaiting eagerly...
                • 4626
                • 57 Posts
                Do you have some kind of log viewer so that you can se what the rewrite_log is saying? If so could you post a chunk of it where it is trying to access a css or image file?

                Does it work if you only use $1 instead of http://domain/$1
                  • 24278
                  • 165 Posts
                  The log extract...
                  127.0.0.1 - - [17/Mar/2007:10:19:30 +0530] "GET / HTTP/1.1" 200 3344
                  127.0.0.1 - - [17/Mar/2007:10:19:39 +0530] "GET /assets/images/favicon.ico HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:39 +0530] "GET /assets/templates/ap/a/print.css HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:39 +0530] "GET /assets/templates/ap/a/sitestyle_2007011901.css HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:39 +0530] "GET /assets/images/feed-icon-16x16.gif HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:39 +0530] "GET /assets/images/content/prj_clau_leha/0.jpg HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:40 +0530] "GET /assets/images/content/prj_lego_juarez/0.jpg HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:40 +0530] "GET /assets/images/content/prj_clau_uqam/0.jpg HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:39 +0530] "GET /assets/images/content/prd_mich_oyon/0.jpg HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:40 +0530] "GET /assets/images/submit_newsletter.gif HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:40 +0530] "GET /assets/images/favicon.ico HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:40 +0530] "GET /assets/images/favicon.ico HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /go/projects/art-ville.html HTTP/1.1" 302 386
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /go/projects/art-ville HTTP/1.1" 200 2772
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /assets/images/favicon.ico HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /assets/templates/ap/a/print.css HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /assets/templates/ap/a/sitestyle_2007011901.css HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /assets/images/content/prj_clau_leha/1.jpg HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /assets/images/feed-icon-16x16.gif HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /assets/images/content/prj_clau_leha/2.jpg HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /assets/images/tell_a_friend.gif HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /assets/images/submit_newsletter.gif HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /assets/images/favicon.ico HTTP/1.1" 404 1597
                  127.0.0.1 - - [17/Mar/2007:10:19:51 +0530] "GET /assets/images/favicon.ico HTTP/1.1" 404 1597
                  

                  It gives a 404 but the files exist and if I disable the .htaccess rule, then it works fine.
                  No, it does not work as expected when http://domain/$1 id replaced with only $1

                  This is what the logs show, when the above replacement is made...

                  127.0.0.1 - - [17/Mar/2007:10:25:21 +0530] "GET /go/projects/art-ville.html HTTP/1.1" 302 416
                  127.0.0.1 - - [17/Mar/2007:10:25:21 +0530] "GET /E:/xampp1.5.5/xampp/htdocs/ap/go/projects/art-ville HTTP/1.1" 403 1099
                  127.0.0.1 - - [17/Mar/2007:10:25:22 +0530] "GET /favicon.ico HTTP/1.1" 404 1597
                  
                    • 25663 MODX Staff
                    • 12,272 Posts
                    Looks like you need to tweak a base href setting. Please provide your:

                    • web root folder,
                    • MODx root folder,
                    • .htaccess file contents (strip out the comments), and
                    • base-href in your template.

                    Thanks!
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Did you try adding
                      Options +FollowSymlinks
                      just before the RewriteEngine On line?
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org