htaccess: Unterseiten sind nach 301-Weiterleitung nicht mehr erreichbar

kranzla

Newbie
Registriert
Sep. 2022
Beiträge
3
Hallo,

ich nutze Wordpress und habe folgende URLs:
Code:
https://www.domainname.de/
https://www.domainname.de/leistungen/
https://www.domainname.de/leistungen/sugbpage-a/
https://www.domainname.de/leistungen/sugbpage-b/
https://www.domainname.de/leistungen/sugbpage-c/

Ich möchte, dass https://www.domainname.de/leistungen/ weitergeleitet wird auf die Startseite https://www.domainname.de/.

Ich hab etwas gegoogelt und dann versucht die Weiterleitung mithilfe von redirect 301 einzurichten:

Code:
# 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.domainname.de$ [NC]
    RewriteRule ^(.*)$ https://www.domainname.de/$1 [L,R=301]
    
    RewriteCond %{SERVER_PORT} !=443
    RewriteRule ^(.*)$ https://www.domainname.de/$1 [R=301,L]
      
</IfModule>


 # 301-redirect
 RewriteEngine On
 Redirect 301 /leistungen/ https://www.domainname.de/


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


Ich hatte aber anschließend das Problem, dass die Unterseiten
https://www.domainname.de/leistungen/sugbpage-a/
https://www.domainname.de/leistungen/sugbpage-b/
https://www.domainname.de/leistungen/sugbpage-c/

nicht mehr aufrufbar waren. Diese Unterseiten sollen weiterhin ganz normal aufrufbar sein

Leider kenne ich mich nicht sonderlich gut aus mit htaccess aus und habe jetzt schon den halben Tag mit diesem Fehler verbracht.

Könnte ihr mir helfen wie ich das genau schreiben muss?

Zudem habe ich irgendwo gelesen, dass man „RewriteEngine On“ nicht mehrmals im htaccess-File verwenden darf. Wie kann ich das sonst lösen?
 
Danke für deine Antwort!

Meinst du ich sollte den Wordpress-Block
Code:
# 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
ganz nach unten verscheiben? Warum?


Ich hätte noch eine weitere Frage:
Ich hatte vor der Umstrukturierung eine weitere Unterseite https://www.domainname.de/ratgeber/, welche jetzt aber nicht mehr exisitert. Ich möchte sie aus SEO-Gründen jetzt auch per RedirectMatch 301 weiterleiten. Muss ich diese Unterseite https://www.domainname.de/ratgeber/ in Wordpress-Backend als leere Seite noch anlegen, obwohl ja der Inhalt seit der Umstrukturierung nicht mehr existiert?
 
Also ich denke es gibt keinen technischen Grund, aber alles das automatisiert bearbeitet wird (Permalinks durchspeichern) am Ende zu halten erleichtert die spätere Wartung (Andere Plugins tragen da auch schon mal Sachen ein).

Ansonsten sollte das ebenfalls mittes htaccess redirect machbar sein. wenn du eine backendverwaltung für redirects (mit automatischer verfolgung von umbenennungen) suchst gibt es das Plugin Redirection
 
  • Gefällt mir
Reaktionen: kranzla
Alles klar, danke.
Aber zu meiner zweiten Frage: Muss ich die Unterseite https://www.domainname.de/ratgeber/ denn in Wordpress-Backend als leere Seite noch anlegen, obwohl ja der Inhalt seit der Umstrukturierung nicht mehr existiert? Oder kann man auch eine nicht-angelegte Seite weiterleiten?
 
Zurück
Oben