Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [htaccess] Subdomena i jej przekierowanie
Mike0
post
Post #1





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 10.03.2011

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


Dzień dobry,

Jako, że nie znalazłem w internecie nic co by mi pomogło rozwiązać swój problem, zwracam się do Was.

Potrzebuję stworzyć wpisy do htaccess, tak by:
  1. sub.domain.com wskazywała na plik /subdomena.php znajdujący się w katalogu głównym strony
  2. sub.domain.com* przekierowywała na domenę domain.com/* zachowując wszystko w miejscu * np. sub.domain.com/controller/action?aaa -> domain.com/controller/action?aaa

Uwaga: sub.domain.com i domain.com wskazują na ten sam katalog

Ja jedyne co sensownego spłodziłem w tym temacie to:
Kod
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^sub.domain.com$
    RewriteRule ^(.*)$ http://sub.domain.com/subdomena.php [L,NC,QSA]

Lecz to przekierowuje, a nie wskazuje na plik subdomena.php ....

Bardzo proszę o pomoc,
z poważaniem
Mike

Ten post edytował Mike0 25.06.2014, 21:24:38
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%)
-----


Zainteresuje się warunkiem opartym na REQUEST_URI.
Go to the top of the page
+Quote Post
Mike0
post
Post #3





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 10.03.2011

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


Patrzyłem na REQUEST_URI, ale to jedynie nadaje sie do warunku czy coś jest poza subdomeną tylu /index.php etc, chyba że coś pomyliłem.

Główmy problemem jest dla mnie uzyskanie 1. warunku jaki dałem czyli aby "sub.domain.com wskazywała na plik /subdomena.php znajdujący się w katalogu głównym strony" i tu proszę nadal o pomoc
Go to the top of the page
+Quote Post
Pyton_000
post
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Kod
    RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^(.*)$ http://sub.domain.com/subdomena.php [L]

    RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
    RewriteCond %{REQUEST_URI} ^/(.*)$
    RewriteRule ^(.*)$ http://sub.domain.com/$1 [L]


Coś w ten deseń

Specem nie jestem.

Polecam: http://htaccess.madewithlove.be/

Ten post edytował Pyton_000 30.06.2014, 18:04:31
Go to the top of the page
+Quote Post
Mike0
post
Post #5





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 10.03.2011

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


@Pyton_000, dzięki za udział w dyskusji. Twój kod działa, z tym że w 1. regule dochodzi do przekierowania, a mi jednak zależy by użytkownik pozostał w sub-domenie... Do 2 reguły nie mam zastrzeżeń (IMG:style_emoticons/default/wink.gif)

Ps. Fajna stronka do testowania (IMG:style_emoticons/default/wink.gif) Przyda się!

--Edit:

Przeklikałem to na szybko i doszedłem do kodu:
Kod
    RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
    RewriteCond %{REQUEST_URI} ^/$ [OR]
    RewriteCond %{REQUEST_URI} ^/subdomena.php$ [OR]
    RewriteRule ^(.*)$ /subdomena.php [L]

    RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
    RewriteCond %{REQUEST_URI} ^/(.*)$
    RewriteRule ^(.*)$ http://domain.com/$1 [L]


Wtedy nie mam przekierowania 1 pierwszym wypadku, jednak dostaję error 500 jak zakładam z powodu pętli, że odwołuje się do pliku subdomena.php który następnie odwołuje się nieskończenie sam do siebie. Jakieś pomysły?

Ten post edytował Mike0 30.06.2014, 20:49:06
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%)
-----


RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
RewriteCond %{REQUEST_URI} ^(/*)$
RewriteRule ^(.*)$ http://sub.domain.com/subdomena.php [L]

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
RewriteCond %{REQUEST_URI} ^/(.+)$
RewriteRule ^(.*)$ http://domena.com/$1 [L]
Go to the top of the page
+Quote Post
Mike0
post
Post #7





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 10.03.2011

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


Nadal wychodzi z domeny, sub.domain.com -> domain.com/subdomain.php
(IMG:style_emoticons/default/sciana.gif)
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%)
-----


Jak wygląda cały .htaccess?
Przy jakim dokładnie adresie wychodzi na pełną domenę?
Go to the top of the page
+Quote Post
Mike0
post
Post #9





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 10.03.2011

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


Dokładnie tak jak napisałem:

http://sub.domain.com -> http://domain.com/subdomain.php

Jeśli chodzi Ci o dokładną domenę pod którą to testuje to niestety nie mogę jej ujawnić, zresztą i tak jest zabezpieczona hasłem.

.htaccess:
Kod
<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
    RewriteCond %{REQUEST_URI} ^(/*)$
    RewriteRule ^(.*)$ http://sub.domain.com/subdomain.php [L]

    RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
    RewriteCond %{REQUEST_URI} ^/(.+)$
    RewriteRule ^(.*)$ http://domain.com/$1 [L]

    RewriteRule ^page,([^-]*)-([^-]*).php$ /pages/$2 [L,R]

    RewriteRule ^user-([^-]*)$ /user/$1 [L,R=301,NC]

#CakePHP standard

    RewriteRule ^$ app/webroot/    [L]
    RewriteRule (.*) app/webroot/$1 [L]

</IfModule>
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%)
-----


A tak?

Kod
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
RewriteCond %{REQUEST_URI} ^(/*)$
RewriteRule ^(.*)$ http://sub.domain.com/subdomena.php [L]

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
RewriteCond %{REQUEST_URI} ^/(.+)$
RewriteCond %{REQUEST_URI} !^/subdomena\.php$
RewriteRule ^(.*)$ http://domena.com/$1 [L]
Go to the top of the page
+Quote Post
Mike0
post
Post #11





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 10.03.2011

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


(IMG:style_emoticons/default/arrowheadsmiley.png) Teraz przekierowuje http://sub.domain.com -> http://sub.domain.com/subdomain.php, a ja jednak chciałbym ukryć /subdomain.php...

Masakra jakaś
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%)
-----


Kod
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
RewriteCond %{REQUEST_URI} ^(/*)$
RewriteRule ^(.*)$ http://sub.domain.com/subdomena.php [L]

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
RewriteCond %{THE_REQUEST} ^GET.*subdomena\.php [NC]
RewriteRule (.*?)subdomena\.php/*(.*) /$1$2 [R=301,NE,L]

RewriteCond %{HTTP_HOST} ^sub\.domain\.com$
RewriteCond %{REQUEST_URI} ^/(.+)$
RewriteCond %{REQUEST_URI} !^/subdomena\.php$
RewriteRule ^(.*)$ http://domena.com/$1 [L]


Go to the top of the page
+Quote Post
Mike0
post
Post #13





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 10.03.2011

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


Nie do końca to zadziałało, ale już jakoś sobie poradzę przy użyciu PHP, będzie łatwiej choć mniej elegancko...
Wielkie dzięki za pomoc (IMG:style_emoticons/default/wink.gif)

Ten post edytował Mike0 4.07.2014, 12:46:00
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: 22.08.2025 - 21:25