Help Cấu hình redirect cho file htaccess

Shu Sakamaki

Corporal
Mọi người giúp em cấu hình với ạ, forum em có chứng chỉ SSL và không dùng subdomain www.
Domain của forum em có dạng như thế này https://domain.com/forum thì cấu hình như nào là đúng ạ?
em cấu hình như dưới đây nhưng không có tác dụng gì :(
Mã:
#    Mod_security can interfere with uploading of content such as attachments. If you

#    cannot attach files, remove the "#" from the lines below.

#<IfModule mod_security.c>

#    SecFilterEngine Off

#    SecFilterScanPOST Off

#</IfModule>



ErrorDocument 401 default

ErrorDocument 403 default

ErrorDocument 404 default

ErrorDocument 405 default

ErrorDocument 406 default

ErrorDocument 500 default

ErrorDocument 501 default

ErrorDocument 503 default



<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    RewriteCond %{HTTP_HOST} !^domain\.com/forum$ [NC]
    RewriteRule ^(.*)$ http://domain.com/forum/$1 [R=301,L,QSA]

    #    If you are having problems with the rewrite rules, remove the "#" from the

    #    line that begins "RewriteBase" below. You will also have to change the path

    #    of the rewrite to reflect the path to your XenForo installation.

    #RewriteBase /xenforo



    #    This line may be needed to enable WebDAV editing with PHP as a CGI.

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



    RewriteCond %{REQUEST_FILENAME} -f [OR]

    RewriteCond %{REQUEST_FILENAME} -l [OR]

    RewriteCond %{REQUEST_FILENAME} -d

    RewriteRule ^.*$ - [NC,L]

    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]

    RewriteRule ^.*$ index.php [NC,L]

</IfModule>
mong cao nhân nào đó giúp em.
 
  • Like
Reactions: THB
Mã:
#########################
# redirect www to no-www
#########################
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]

#########################
# redirect port 80 to https (đã test):
# Always use https for secure connections
# Replace 'domain.com' with your domain name
# (as it appears on your SSL certificate)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
 
Theo mình đoán thì server của bạn cấu hình sai trong httpd.conf, làm cho file .htaccess có mà cũng như không, nó không áp dụng.

Để kiểm tra có phải đúng là .htaccess không hoạt động thì bạn đưa vào file này dòng sau:
# disable directory browsing
Options All -Indexes

Rồi tạo một thư mục trống, ví dụ: https://domain.com/forum/test
Vào thử thư mục này, coi có hiển thị dạng "index of" không hay là báo lỗi không xem được. Nếu hiển thị dạng index of, thì đích thị là file .htaccess không được áp dụng rồi.

Phải vào chỉnh trong httpd.conf lại thành:

<Directory "/var/www/html">
AllowOverride All
Require all granted
</Directory>

Mình chỉ đoán thôi, và mong giúp được ý gì đó để bạn kiểm tra lại, vì đã từng dính vụ .htaccess có như không mà cứ tưởng nó đang hoạt động.
 
Theo mình đoán thì server của bạn cấu hình sai trong httpd.conf, làm cho file .htaccess có mà cũng như không, nó không áp dụng.

Để kiểm tra có phải đúng là .htaccess không hoạt động thì bạn đưa vào file này dòng sau:
# disable directory browsing
Options All -Indexes

Rồi tạo một thư mục trống, ví dụ: https://domain.com/forum/test
Vào thử thư mục này, coi có hiển thị dạng "index of" không hay là báo lỗi không xem được. Nếu hiển thị dạng index of, thì đích thị là file .htaccess không được áp dụng rồi.

Phải vào chỉnh trong httpd.conf lại thành:

<Directory "/var/www/html">
AllowOverride All
Require all granted
</Directory>

Mình chỉ đoán thôi, và mong giúp được ý gì đó để bạn kiểm tra lại, vì đã từng dính vụ .htaccess có như không mà cứ tưởng nó đang hoạt động.
cảm ơn anh ạ :D
 
Mình áp dụng code dưới vẫn không được, có ai giúp mình không ?


#########################
# redirect www to no-www
#########################
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,NE,L]

#########################
# redirect port 80 to https (đã test):
# Always use https for secure connections
# Replace 'domain.com' with your domain name
# (as it appears on your SSL certificate)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://f123.vn/$1 [R=301,L]

chuyen f123.PNG
 
Back
Top