Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [htaccess] Dopisanie .html na końcu urla
djgarsi
post
Post #1





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Witam.
Mam krótkie pytanko odnośnie .htaccess'a.
W jaki sposób dopisać (301) do url'a frazę .html?

Mam linki typu domena.pl/blog-p14/tytul-artykulu
Chciałbym osiągnąć przekierowanie tego na domena.pl/blog-p14/tytul-artykulu.html

Jest to możliwe aby dać przekierowanie 301?
Go to the top of the page
+Quote Post
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Jest, ale musisz mieć fizycznie istniejące pliki .html lub przepisywanie adresów z .html w htaccess

  1. RewriteCond %{HTTP_HOST} domena.pl
  2. RewriteCond %{REQUEST_URI} ^/(.*)/(.*)
  3. RewriteRule .* /%1/%2.html [L,R=301]


lub tylko z adresu zawierającego /blog-p14/
  1. RewriteCond %{HTTP_HOST} domena.pl
  2. RewriteCond %{REQUEST_URI} ^/blog-p14/(.*)
  3. RewriteRule .* /blog-p14/%1.html [L,R=301]
Go to the top of the page
+Quote Post
djgarsi
post
Post #3





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


A jeśli mam generowane dynamicznie linki np.
domena.pl/blog-p14/tytul-artykulu
domena.pl/blog-p16/tytul-artykulu-2
domena.pl/blog-p17/tytul-artykulu-3
domena.pl/blog-p18/tytul-artykulu-4
itd

Da się coś z tym zrobić?
Ogólnie chodzi o to żeby Google nie marudziło bo 404 będzie wywalać. W związku z tym trzeba by to przekierowanie zrobić.
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


No, to musisz je generować z końcówką .html, a w htaccess zmienić przepisywanie przyjaznych URLi na nieprzyjazne (czyli dodać tam .html).

EDIT: A potem przekierowanie, które podałem wyżej, żeby nie było duplicate content. 404.

Ten post edytował trueblue 7.08.2014, 10:13:27
Go to the top of the page
+Quote Post
djgarsi
post
Post #5





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Wiem wiem. Obecnie już generuję je z końcówką .html. Jednak chciałbym zrobić przekierowanie z tych starych bo są zaindeksowane jeszcze bez końcówki. Wg mnie Google potraktuje te linki jako nowe i moc ich będzie budowana od zera.
Go to the top of the page
+Quote Post
trueblue
post
Post #6





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


To właśnie, to co podałem w drugim poście z "bez .html" na ".html".
Go to the top of the page
+Quote Post
djgarsi
post
Post #7





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


W Chrome wyrzuca że strona zawiera pętlę przekierowań.
A w Firefox dodaje z 10 razy .html.html.html.html itd

Ten post edytował djgarsi 7.08.2014, 10:18:05
Go to the top of the page
+Quote Post
trueblue
post
Post #8





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


To nie zależy od przeglądarki.

Pokaż jak wygląda cały htaccess.
Go to the top of the page
+Quote Post
djgarsi
post
Post #9





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Oto mój htaccess:

Kod
<IfModule mod_deflate.c>
    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
    </IfModule>
</IfModule>

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^domena.pl$
RewriteRule ^(.*)$ http://www.domena.pl/$1 [R=301,L]

RewriteRule ^blog.html$ index.php?page=blog [L,NC]
RewriteRule ^blog-p([0-9]*)/(.*).html$ index.php?page=blogpost&id=$1 [L,NC]

RewriteRule ^rss.xml$ rss/rss.php [L,NC]

ErrorDocument 404 /404.php
Go to the top of the page
+Quote Post
trueblue
post
Post #10





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Na razie masz tu przepisywanie z .html na nieprzyjazne.
Wygląda ok.
Może w kodzie masz przekierowania za pomocą header?
Po wpisaniu jakiego adresu wpada w pętlę?
Go to the top of the page
+Quote Post
djgarsi
post
Post #11





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Po dodaniu pierwszego lub drugiego kodu zachowuje się tak samo.
Wpisując domena.pl/blog-p16/tytul-artykulu-2 z i bez .html jest to samo.

Nie robiłem przekierowań za pomocą header.
Go to the top of the page
+Quote Post
trueblue
post
Post #12





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Ok, pokaż htaccess po zmianach.
Go to the top of the page
+Quote Post
djgarsi
post
Post #13





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Kod
<IfModule mod_deflate.c>
    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
    </IfModule>
</IfModule>

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^domena.pl$
RewriteRule ^(.*)$ http://www.domena.pl/$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^/(.*)/(.*)
RewriteRule .* /%1/%2.html [L,R=301]

RewriteRule ^blog.html$ index.php?page=blog [L,NC]
RewriteRule ^blog-p([0-9]*)/(.*).html$ index.php?page=blogpost&id=$1 [L,NC]

RewriteRule ^rss.xml$ rss/rss.php [L,NC]

ErrorDocument 404 /404.php
Go to the top of the page
+Quote Post
trueblue
post
Post #14





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


  1. RewriteCond %{REQUEST_URI} ^/(.*)/(.*)
  2. RewriteCond %{REQUEST_URI} !.html$
  3. RewriteRule .* /%1/%2.html [L,R=301]
Go to the top of the page
+Quote Post
djgarsi
post
Post #15





Grupa: Zarejestrowani
Postów: 459
Pomógł: 26
Dołączył: 1.06.2009

Ostrzeżenie: (0%)
-----


Dziwne rzeczy się dzieją.
Po dodaniu tego kodu kody CSS przestały działać.
Go to the top of the page
+Quote Post
trueblue
post
Post #16





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


  1. RewriteCond %{REQUEST_FILENAME} !-f
  2. RewriteCond %{REQUEST_FILENAME} !-d
  3. RewriteCond %{REQUEST_URI} ^/(.*)/(.*)
  4. RewriteCond %{REQUEST_URI} !.html$
  5. RewriteRule .* /%1/%2.html [L,R=301]
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 18.09.2025 - 17:36