Przekierowanie .htaccess indexphp/html

0

Witajcie,
Mam taki .htaccess.
Chciałbym:

  1. Żeby z www.domena.pl kierował na domena.pl (to mam zrobione)
  2. żeby zawsze kierował na https
  3. żeby po wpisaniu domena.pl/index php lub html -> kierował na domena.pl

W jaki sposób można to zrobić?

Mój htacess:

 RewriteEngine On
    # Redirect to non www
    RewriteCond %{HTTP_HOST} ^www.domena.pl$ [NC]
    RewriteRule ^(.*)$ https://domena.pl/$1 [R=301,L]


0
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Za poniższe nie dam głowy, ale to powinno być coś w tym guście.
(O ile ci taki mechanizm jakiejś pętli przekierowań nie zrobi).

RewriteCond %{REQUEST_URI} ^/index.htm*$
RewriteRule (.*) [R]

RewriteCond %{REQUEST_URI} ^/index.php*$
RewriteRule (.*) [R]
0

@Freja Draco: Niestety nie działa. :( W dalszym ciągu wyświetla index.php (nie robi przekierowania), a index.html zgłasza 404

1

Spróbuj

RewriteCond %{REQUEST_URI} ^\/index.php$
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)$ https://www.twojadomena.pl/ [L,R=301]
0

@NewUser2k13: Niestety, to powoduje przekierowanie z innych stron także na stronę główną - nie tylko z index :(

1

A tak?

RewriteCond %{REQUEST_URI} ^/index.php$
RewriteRule (.*) / [R]

RewriteCond %{REQUEST_URI} ^/index.htm$
RewriteRule (.*) / [R]

https://htaccess.madewithlove.be/

0

Aż poszłam sprawdzić:

RewriteCond %{REQUEST_URI} ^/index.php$
RewriteRule (.*) / [R]

RewriteCond %{REQUEST_URI} ^/index.htm$
RewriteRule (.*) / [R]

Zasadniczo działają, ale jeżeli domyślnym dokumentem jest np: index.php, a jednocześnie użyjesz powyższych dyrektyw, to (tak jak podejrzewałam) serwer wpada w pętlę przekierowań. Mógłbyś ew. zdefiniować inny dokument domyślny niż domyślnie domyślny index.php, ale moim zdaniem po prostu przekombinowujesz. Odpuść sobie te przekierowania.

0

@Freja Draco: Jak wypisuje index.php - to wyświetla mi adres.pl/index.php, a jak zmienię na index.html - to mam 404 not found :(

0
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Redirect to non www
    RewriteCond %{HTTP_HOST} ^www.domena.pl$ [NC]
    RewriteRule ^(.*)$ https://domena.pl/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^/index.php$
RewriteRule (.*) / [R]

RewriteCond %{REQUEST_URI} ^/index.htm$
RewriteRule (.*) / [R]


    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Fonts
    # Add correct content-type for fonts
    AddType application/vnd.ms-fontobject .eot
    AddType application/x-font-ttf .ttf
    AddType application/x-font-opentype .otf
    AddType application/x-font-woff .woff
    AddType image/svg+xml .svg

    ExpiresActive On
    ExpiresByType image/jpg "access plus 3 month"
    ExpiresByType image/jpeg "access plus 3 month"
    ExpiresByType image/gif "access plus 3 month"
    ExpiresByType image/png "access plus 3 month"
    ExpiresByType text/css "access plus 3 month"
    ExpiresByType application/pdf "access plus 3 month"
    ExpiresByType text/javascript "access plus 3 month"
    ExpiresByType application/javascript "access plus 3 month"
    ExpiresByType application/x-javascript "access plus 3 month"
    ExpiresByType application/x-shockwave-flash "access plus 3 month"
    ExpiresByType image/x-icon "access plus 3 month"
    ExpiresByType image/ico "access plus 3 month"

    ExpiresByType text/css "access plus 3 month"
    ExpiresByType text/css "now plus 1 month"
    ExpiresByType application/vnd.ms-fontobject "access plus 3 month"
    ExpiresByType application/x-font-ttf "access plus 3 month"
    ExpiresByType application/x-font-opentype "access plus 3 month"
    ExpiresByType application/x-font-woff "access plus 3 month"
    ExpiresByType image/svg+xml "access plus 3 month"
    ExpiresByType text/html "access plus 600 seconds"

    ExpiresDefault "access plus 2 days"

</IfModule>

Strona jest na Laravelu

0

Spróbuj tak:

RewriteEngine On

# Redirect to non www
RewriteCond %{HTTP_HOST} ^www.domena.pl$ [NC]
RewriteRule ^(.*)$ https://domena.pl/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^/index.php$
RewriteRule (.*) / [R]

RewriteCond %{REQUEST_URI} ^/index.htm$
RewriteRule (.*) / [R]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Fonts
# Add correct content-type for fonts
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/x-font-woff .woff
AddType image/svg+xml .svg

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    ExpiresActive On
    ExpiresByType image/jpg "access plus 3 month"
    ExpiresByType image/jpeg "access plus 3 month"
    ExpiresByType image/gif "access plus 3 month"
    ExpiresByType image/png "access plus 3 month"
    ExpiresByType text/css "access plus 3 month"
    ExpiresByType application/pdf "access plus 3 month"
    ExpiresByType text/javascript "access plus 3 month"
    ExpiresByType application/javascript "access plus 3 month"
    ExpiresByType application/x-javascript "access plus 3 month"
    ExpiresByType application/x-shockwave-flash "access plus 3 month"
    ExpiresByType image/x-icon "access plus 3 month"
    ExpiresByType image/ico "access plus 3 month"

    ExpiresByType text/css "access plus 3 month"
    ExpiresByType text/css "now plus 1 month"
    ExpiresByType application/vnd.ms-fontobject "access plus 3 month"
    ExpiresByType application/x-font-ttf "access plus 3 month"
    ExpiresByType application/x-font-opentype "access plus 3 month"
    ExpiresByType application/x-font-woff "access plus 3 month"
    ExpiresByType image/svg+xml "access plus 3 month"
    ExpiresByType text/html "access plus 600 seconds"

    ExpiresDefault "access plus 2 days"

</IfModule>
0

Może:

RewriteCond %{REQUEST_URI} ^/index.php$
RewriteRule (.*) / [R,L]

RewriteCond %{REQUEST_URI} ^/index.htm$
RewriteRule (.*) / [R,L]

Niech się jakiś .htaccess-owy matasza w wątku ujawni :)

0

@Freja Draco: teraz przestały działać linki na stronie - wszystko kieruje na główną :(

0

Skoro jest laravel to nie wystarczy odpowiednio ustawić routingu bez grzebania w htaccess?

0

@PaulGilbert: rutami udało mi się ogarnąć index.html. Została kwestia index.php :) dzięki za sugestię :)

0

Pomogło coś takiego:

RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^index.php(.*)$ /$1 [R=301,L]

Dziękuję bardzo za pomoc :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1