Home > Back-end >  subpage is not accessible after 301-redirect in .htaccess
subpage is not accessible after 301-redirect in .htaccess

Time:09-20

I want https://www.example.com/ca-report/ to be redirected to the front page https://www.example.com/.

But when I tried to place a 301 redirect for https://www.example.com/ca-report/ in .htaccess, unfortunately the subpage https://www.example.com/ca-report/subpage is not accessible anymore.

I guess I did something wrong. Could you please review my .htaccess code and help me?

btw: I am not sure if I am allowed to use RewriteEngine On several times as I did.

Here is my unsuccessful try:

# BEGIN iThemes Security - Do not modify or remove this line
# iThemes Security Config Details: 2
    # Protect System Files - Security > Settings > System Tweaks > System Files
    <files .htaccess>
        <IfModule mod_authz_core.c>
            Require all denied
        </IfModule>
        <IfModule !mod_authz_core.c>
            Order allow,deny
            Deny from all
        </IfModule>
    </files>
    <files readme.html>
        <IfModule mod_authz_core.c>
            Require all denied
        </IfModule>
        <IfModule !mod_authz_core.c>
            Order allow,deny
            Deny from all
        </IfModule>
    </files>
    <files readme.txt>
        <IfModule mod_authz_core.c>
            Require all denied
        </IfModule>
        <IfModule !mod_authz_core.c>
            Order allow,deny
            Deny from all
        </IfModule>
    </files>
    <files wp-config.php>
        <IfModule mod_authz_core.c>
            Require all denied
        </IfModule>
        <IfModule !mod_authz_core.c>
            Order allow,deny
            Deny from all
        </IfModule>
    </files>

    # Disable Directory Browsing - Security > Settings > System Tweaks > Directory Browsing
    Options -Indexes

    <IfModule mod_rewrite.c>
        RewriteEngine On

        # Protect System Files - Security > Settings > System Tweaks > System Files
        RewriteRule ^wp-admin/install\.php$ - [F]
        RewriteRule ^wp-admin/includes/ - [F]
        RewriteRule !^wp-includes/ - [S=3]
        RewriteRule ^wp-includes/[^/] \.php$ - [F]
        RewriteRule ^wp-includes/js/tinymce/langs/. \.php - [F]
        RewriteRule ^wp-includes/theme-compat/ - [F]
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule (^|.*/)\.(git|svn)/.* - [F]

        # Disable PHP in Uploads - Security > Settings > System Tweaks > PHP in Uploads
        RewriteRule ^wp\-content/uploads/.*\.(?:php[1-7]?|pht|phtml?|phps)\.?$ - [NC,F]

        # Disable PHP in Plugins - Security > Settings > System Tweaks > PHP in Plugins
        RewriteRule ^wp\-content/plugins/.*\.(?:php[1-7]?|pht|phtml?|phps)\.?$ - [NC,F]

        # Disable PHP in Themes - Security > Settings > System Tweaks > PHP in Themes
        RewriteRule ^wp\-content/themes/.*\.(?:php[1-7]?|pht|phtml?|phps)\.?$ - [NC,F]
    </IfModule>
# END iThemes Security - Do not modify or remove this line

# 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.
<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



# redirect to https & www
<IfModule mod_rewrite.c>
    
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
    RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
    
    RewriteCond %{SERVER_PORT} !=443
    RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
    
</IfModule>


 # 301-redirect
 RewriteEngine On
 Redirect 301 /ca-report/ https://www.example.com/


<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml xml
AddOutputFilterByType DEFLATE application/rss xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>


EDIT:

@MrWhite now I understand a bit more about htaccess after your detailed explanations. As I said the htaccess-code has changed slightly in the meantime because of another plugin. And additionally I added a redirect for www.example.com/ca-writing/.

www.example.com
  www.example.com/ca-report/    #should be redirected to front page www.example.com
    www.example.com/ca-report/subpage   # should be accessible normally
  www.example.com/ca-writing/   # should be redirected to front page www.example.com for SEO-reason, since this URL doesn’t exist anymore after the website restructuring

I have implemented your tips now

  • Related