301 Перенаправить blog.example.com на www.example.com/blog с помощью htaccess в Ubuntu/Codeigniter4/Wordpress.Php

Кемеровские программисты php общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 301 Перенаправить blog.example.com на www.example.com/blog с помощью htaccess в Ubuntu/Codeigniter4/Wordpress.

Сообщение Anonymous »

У меня есть блог, который в настоящее время размещен на моем субдомене, и я хотел бы переместить его в подкаталог /blog. На основном веб-сайте используется фреймворк CodeIgniter4, а в блоге — Wordpress. Он размещен на сервере Apache с использованием Ubuntu. Я могу перенаправить корень blog.example.com на www.example.com/blog, но не могу перенаправить blog.example.com/123 на www.example.com/blog/123Вот файл .htaccess для веб-сайта (я добавил строку RewriteCond $1 !^(index\.php|blog), но основную часть файла я включил для справки:

Код: Выделить всё

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.

Options +FollowSymlinks
RewriteEngine On

# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /

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

# Rewrite "www.example.com -> example.com"
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|blog)
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

# Ensure Authorization header is passed along
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Вот htaccess для блога:

Код: Выделить всё

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .  /index.php [L]


# END WordPress

RewriteCond %{HTTP_HOST} ^blog\.example\.com
RewriteRule ^(.*)$ https://www.example.com/blog/$1 [R=301]
А вот файл конфигурации Apache для www.example.com:

Код: Выделить всё

ServerAdmin [email protected]
ServerName www.example.com
ServerAlias www.example.com

Protocols h2 http/1.1

DocumentRoot /var/www/example-website/public


SetEnv website
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted


Alias /blog "/var/www/example-blog/public_html"


SetEnv blog
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted


ErrorLog /var/www/example-website/writable/logs/errors.log
CustomLog /var/www/example-website/writable/logs/access.log combined env=website
CustomLog /var/www/example-blog/public_html/wp-content/access.log combined env=blog

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Для справки, вот файл конфигурации HTTPS, созданный certbot:

Код: Выделить всё


ServerAdmin [email protected]
ServerName www.example.com
ServerAlias www.example.com

Protocols h2 http/1.1

Alias /blog "/var/www/example-blog/public_html"


SetEnv blog
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted


DocumentRoot /var/www/example-website/public


Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted


ErrorLog /var/www/example-website/writable/logs/errors.log
CustomLog /var/www/example-website/writable/logs/access.log combined env=website
CustomLog /var/www/example-blog/public_html/wp-content/access.log combined env=blog

RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.

#      RewriteCond %{SERVER_NAME} =www.example.com
#      RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.example.com-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com-0001/privkey.pem


Кроме того, что касается файла конфигурации, есть ли способ создать отдельный журнал ошибок для блога?

Подробнее здесь: https://stackoverflow.com/questions/783 ... n-ubuntu-c
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Php»