• Resolved discombobulated

    (@discombobulated)


    Hello and thanks in advance of any help!

    My question is one about modifying an existing .htaccess file (I didn’t code the existing one, it’s something I have inherited. Can anyone please help?

    The EXISTING .htaccess file reads as follows:

    Redirect 301 /example_page_1.html http://www.domain-name.com/?products=example-product-1
    Redirect 301 /example_page_2.html http://www.domain-name.com/?products=example-product-2
    Redirect 301 /example_page_3.html http://www.domain-name.com/?products=example-product-3

    and on and on and on and finishes:

    Redirect 301 /example_page_500.html http://www.domain-name.com/?products=example-product-500

    ==========================================
    That’s it. (Notice that all these redirects involve “products” and the pretty URL strings are:)

    http://www.domain-name.com/?products=xxxxxxxxxxxxxxx

    ==========================================

    Okay, so much for the content of the existing .htaccess file.

    I now need to add to it; or modify it in some manner so that I can redirect several hundred other pages which are in this format:

    http://www.domain-name.com/?page_id=521

    to the “Post Name” option. ie

    http://www.domain-name.com/post-name/

    This is because when I tweak the permalink settings (either via the standard link in the WP dashboard or via its counterpart in Yoast – all of the resulting “prettier” page links break. I also see the message in the WP Dashboard (or Yoast) advising:

    “If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file.”

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    Question is (finally!) – should I simply paste the lump of code above into the existing .htaccess file, exactly as is? If so, do I paste it above, or below those 500 existing “301 Redirect” lines? Or doesn’t it matter? Possibly, by pasting that <IfModule mod_rewrite.c> code in to the files, I could then REMOVE those 500 other lines?

    One other question – it’s related:

    Should I use this version of the <IfModule mod_rewrite.c> code (includes the # BEGIN and #END tags – found that version elsewhere on the net)

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    Thank you VERY much for any help you might be able to provide!

    D

Viewing 2 replies - 1 through 2 (of 2 total)
  • “If your .htaccess file were writable, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file.”

    This issue there is the permissions setting for your htaccess file, and I keep mine set at 0404 (like yours seems to be at present) to be sure nothing and nobody but me ever changes that file.

    Should I use this version of the <IfModule mod_rewrite.c> code (includes the # BEGIN and #END tags – found that version elsewhere on the net)

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    Yes, and I believe that will work in place of the long list you already have. However, first save a copy of your current htaccess file as a backup.
    note: The # BEGIN WordPress and #END WordPress tags are what tell plugins and such to leave this section alone, but that does not always stop them and that is why I keep my htaccess permissions set at 0404.

    Thread Starter discombobulated

    (@discombobulated)

    leejosepho:

    Many, many thanks for taking the time to answer my question and to do so in such detail. And my apologies for taking so long to come back to you, I was knocked offline for a few days 🙁

    I’ve followed your advice and the “rewrite” code above did the job perfectly; all the old “ugly” URLS are now pretty. It did the job for ALL the URLS too, and I was able to safely delete the 500+ “old” lines of code.

    I am marking this thread as (very well!) resolved and thank you again.

    (I am though about to create a related thread, and hope you might see it; basically, I am curious, now that all the URLS are “pretty” if I should go into Google Webmaster Tools and request removal from the Google index of all those ugly URLS. Hope I might be lucky enough to catch you there later!)

    Many thanks again.

    D

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘.htaccess file – any help please?’ is closed to new replies.