简体   繁体   中英

htaccess - Force rewrite url to use subdirectory

I have address http://example.com/blog which redirects to URL specified in application.
Now I need to 'force' this URL to use subdirectory blog , so when I go to http://example.com/blog it will be use /blog subdirectory.
How can I do this by .htaccess file?

Here is my dir structure:

+- blog/  
+-----index.php
+-----.htaccess
+- app/
+- assets/
+- resources/
+- cache/
+- .htaccess
+- index.php

Current root .htaccess file

RewriteEngine On

#RewriteBase /
#RewriteCond %{HTTP_HOST} !^www.example.com [NC]
#RewriteRule ^(.*)$ https://www.example.com%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_URI} =/sitemap.xml [OR]
RewriteCond %{REQUEST_URI} =/en/sitemap.xml [OR]
RewriteCond %{REQUEST_URI} =/ru/sitemap.xml
RewriteRule .* /?module=toolkits&action=xmlsitemap [L]

RewriteRule !(\.(ico|cdr|js|xml|flv|css|gif|jpe?g|png|tif|swf|doc|xls|pdf|zip|rar|ttf|eot|htc|otf|csv|woff|woff2|svg|mp4|map|txt))$ index.php [L,NC]

<IfModule mod_expires.c>
        <Filesmatch "\.(jpe?g|png|gif|xml|js|css|swf|ico|woff|woff2|ttf|mp3|mp4|map)$">
                ExpiresActive on
                ExpiresDefault "access plus 7 days"
        </Filesmatch>
</IfModule>

<IfModule mod_deflate.c>
    <FilesMatch "\.(js|css|html|php)$">
        SetOutputFilter DEFLATE
    </FilesMatch>
</IfModule>

#<IfModule mod_rewrite.c>
#RewriteEngine On

#
#
#</IfModule>

您需要将RewriteBase指令指向一个文件夹,该文件夹将作为所有相对路径的基础。

RewriteBase "/blog/"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM