Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> .htaccess - przekierowanie bez slasha nie działa
deha21
post 21.01.2018, 09:34:54
Post #1





Grupa: Zarejestrowani
Postów: 544
Pomógł: 5
Dołączył: 18.08.2009

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


Jak zwykle mam problem z .htaccess. Chcę zrobić standardowe przekierowanie z /projects na projects.php i /freebies na freebies.php. Problem jest taki, że gdy wpiszę /projects/ (ze slashem na końcu) to nie działa, gdy wpiszę bez to działa. Natomiast w przypadku /freebies/ (ze slashem) podstrona działa, a bez slasha nie działa... Taki mam kod:
  1. RewriteCond %{HTTPS} !=on
  2. RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
  3. RewriteCond %{HTTP_HOST} ^www.mojastrona.pl [NC]
  4. RewriteRule ^(.*)$ <a href="https://mojastrona.pl/$1" target="_blank">https://mojastrona.pl/$1</a> [L,R]
  5.  
  6. RewriteRule ^projects$ /projects.php [NC]
  7. RewriteRule ^freebies$ /freebies.php [NC]


--------------------
Go to the top of the page
+Quote Post
trueblue
post 21.01.2018, 10:47:14
Post #2





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


Kod
...

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

RewriteCond %{REQUEST_URI} ^/(projects|freebies)/$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/%1.php [NC,L]




--------------------
Go to the top of the page
+Quote Post
deha21
post 21.01.2018, 20:21:28
Post #3





Grupa: Zarejestrowani
Postów: 544
Pomógł: 5
Dołączył: 18.08.2009

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


Z tym, że Twój kod przekierowuje bezpośrednio na pliki .php a jak chciałbym żeby w adresie nie było tego .php


--------------------
Go to the top of the page
+Quote Post
trueblue
post 21.01.2018, 20:38:53
Post #4





Grupa: Zarejestrowani
Postów: 6 761
Pomógł: 1822
Dołączył: 11.03.2014

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


Czyli nie chcesz zrobić przekierowania, ale przepisanie.

Kod
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]

RewriteCond %{REQUEST_URI} ^/(projects|freebies)/$
RewriteRule ^(.*)$ /%1.php [NC,L]


--------------------
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 22:40