• Resolved bus5ojp

    (@bus5ojp)


    Hello,

    I’ve just installed the plugin as I’m told I need to edit my HT Access file to prevent some spammy link/404 issues.

    Here’s exactly what I’m told to do from the guide I’m using:

    “The first step should involve editing the .htaccess file and setting this as the first Rewrite rule:?

    RewriteRule ^1000/?$ – [G]
    RewriteRule /1000/?$ – [G]

    So basically, I’ve got to add this to the ht access file. But I’ve no idea what to do. Is this in place of any existing redirect rules in the file? Alongside other redirect rules? Where exactly in the HT access code do I put this snippet?

    When I tried to put this above the first existing rewrite rule, the test feature told me it was incorrect.

    For everything I’ve tried so far, when I test the changes, I always get the error message that the code syntax has failed and it will break the site. Strangely, I still get this error when I make NO changes to the code, so any help on getting this rewrite rule done correctly would be appreciated,

    Thanks,

    Oliver

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Alexandru Tapuleasa

    (@talextech)

    Hi,

    Rewrite rules can be added after the first RewriteEngine On you can find in your .htaccess or you can just add them at the top of the file like this.

    RewriteEngine On
    RewriteRule ^1000/?$ – [G]
    RewriteRule /1000/?$ – [G]

    The Test Before Saving tool does this:
    – creates a copy of your existing .htaccess file
    – writes the new content to .htaccess
    – attempts to access an index.html file it temporarily creates to check if a 2xx or 3xx status is returned. If it receives a 4xx or 5xx status code it will report the test as failed.

    If your website returns a 500 status code for example for a different reason then the Test tool of htaccess has no way to know and would falsely report it’s an issue with the htaccess file.

    Thread Starter bus5ojp

    (@bus5ojp)

    OK, thanks for your helpful reply. OK, I’m using the plugin and pasting the code where you say after the first Rewrite on, but it’s still giving me a syntax error when I test it.

    Here’s how the code is before (from If Module down):

    </IfModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    And then after I paste the two lines in:

    </IfModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^1000/?$ – [G]
    RewriteRule /1000/?$ – [G]
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    So I’m basically adding the two extra lines of code as line 12 and 13, but not deleting anything else. But still giving me the error. Is the plugin saying there’s a problem when there isn’t? The site is still fine and working before, and also after if I exit the plugin without saving changes.

    Thanks,

    Oliver

    Plugin Author Alexandru Tapuleasa

    (@talextech)

    Well, in your first reply you mentioned ”?still get this error when I make NO changes to the code” so clearly the test result is not accurate in your case.

    But in both cases I see </IfModule> as the first line… unless you only copied part of the .htaccess contents then that orphaned closing </IfModule> would cause a fatal error.

    Try the code without that </IfModule> at the top and see if it passes the test.

    Thread Starter bus5ojp

    (@bus5ojp)

    Sorry I’ll copy the entire code from top to bottom, including the hashtag WORDPRESS opening sections

    Here is it as I originally load it (and yes it still fails the tests even in this state, even though the site works fine):

    # BEGIN WordPress
    # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    Options -Indexes
    <IfModule mod_headers.c>
    	Header set X-Endurance-Cache-Level "0"
    	Header set X-nginx-cache "WordPress"
    </IfModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    # BEGIN ShortPixelWebp
    # The directives (lines) between "BEGIN ShortPixelWebp" and "END ShortPixelWebp" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    
    # END ShortPixelWebp
    # Use PHP71 as default
    #AddHandler application/x-httpd-php71 .php
    #<IfModule mod_suphp.c>
        #suPHP_ConfigPath /opt/php71/lib
    #</IfModule>
    
    # php -- BEGIN cPanel-generated handler, do not edit
    # Set the “ea-php74” package as the default “PHP” programming language.
    <IfModule mime_module>
      AddHandler application/x-httpd-ea-php74___lsphp .php .php7 .phtml
    </IfModule>
    # php -- END cPanel-generated handler, do not edit

    And then once I add the rewrite rules where you said:

    # BEGIN WordPress
    # The directives (lines) between "BEGIN WordPress" and "END WordPress" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    Options -Indexes
    <IfModule mod_headers.c>
    	Header set X-Endurance-Cache-Level "0"
    	Header set X-nginx-cache "WordPress"
    </IfModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^1000/?$ – [G]
    RewriteRule /1000/?$ – [G]
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    # BEGIN ShortPixelWebp
    # The directives (lines) between "BEGIN ShortPixelWebp" and "END ShortPixelWebp" are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    
    # END ShortPixelWebp
    # Use PHP71 as default
    #AddHandler application/x-httpd-php71 .php
    #<IfModule mod_suphp.c>
        #suPHP_ConfigPath /opt/php71/lib
    #</IfModule>
    
    # php -- BEGIN cPanel-generated handler, do not edit
    # Set the “ea-php74” package as the default “PHP” programming language.
    <IfModule mime_module>
      AddHandler application/x-httpd-ea-php74___lsphp .php .php7 .phtml
    </IfModule>
    # php -- END cPanel-generated handler, do not edit

    The rewrite rules are added on lines 12 and 13, nothing else deleted. Does it look correct to you? I may just have to save it anyway and take a chance, even though the test says it’s failed.

    Thanks

    Plugin Author Alexandru Tapuleasa

    (@talextech)

    I see… the code seems OK to me, I don’t know why the test fails. Like I said, it’s probably something else if the code before the change also fails the test. Maybe it’s some firewall blocking the request made by WP Htaccess Editor.

    You will need to edit the file via FTP to be safe, sorry ??

    Thread Starter bus5ojp

    (@bus5ojp)

    OK, thanks, I asked my host to do it. They said they did it, but when I checked the ht access file, the new lines weren’t in there. Is there another way they could have implemented the same rule? Just slightly confused that’s it’s not appearing in the ht access file after they said they changed it

    Update – I did eventually find it in the “home” folder in my cpanel, and then in “public_html” folder, in the ht access file in there. It was changed in there. But I have a bunch of domains on that hosting account, and I wanted this rewrite rule to be applied to ALL the domains, not just the primary one. Will this be applied to all domains if it was changed in just this ht access file?

    • This reply was modified 7 months, 4 weeks ago by bus5ojp.
    Plugin Author Alexandru Tapuleasa

    (@talextech)

    I really can’t say, I have no idea what your host did ??

    Just test it on different domains … if you open domain.com/1000 you should see “Gone” instead of 404 or a page.

    Thread Starter bus5ojp

    (@bus5ojp)

    OK, thanks for your help on this thread ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to set first redirect rule’ is closed to new replies.