![](/img/trans.png)
[英]Rewrite the url of a website living in a subdirectory with .htaccess
[英]htaccess - Force rewrite url to use subdirectory
我有地址http://example.com/blog
,該地址重定向到應用程序中指定的URL。
現在,我需要“強制”該URL來使用子目錄blog
,因此當我轉到http://example.com/blog
,它將使用/blog
子目錄。
我該如何通過.htaccess
文件執行此操作?
這是我的目錄結構:
+- blog/
+-----index.php
+-----.htaccess
+- app/
+- assets/
+- resources/
+- cache/
+- .htaccess
+- index.php
當前的根 .htaccess
文件
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/"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.