Redirect all subdirectory links to another subdirectory

Need to redirect all blog links such as website.com/2015/03/post-title to website.com/blog/2015/03/post-title . So far nothing I used worked – neither redirect, nor redirectmatch.

What happened was the website was redesigned from WordPress to Joomla, so there’s a Joomla .htaccess file on the root of the website, but the blog remained on wordpress so there’s a worpdress installation on /blog with its own .htaccess.

Read More

This is root .htaccess contents:

##### RewriteEngine enabled - BEGIN
RewriteEngine On
RewriteRule ^(d{4}/d{2}/.+)$ /blog/$1 [L,NC,R=301]
##### RewriteEngine enabled - END

##### Custom Rules (Top of File) -- BEGIN
Redirect 301 /practice-areas/construction-law /practice-areas/civil-litigation
Redirect 301 /practice-areas/family-law /practice-areas/civil-litigation
##### Custom Rules (Top of File) -- END

##### File execution order -- BEGIN
DirectoryIndex index.php index.html
##### File execution order -- END

##### No directory listings -- BEGIN
IndexIgnore *
Options -Indexes
##### No directory listings -- END

##### Redirect index.php to / -- BEGIN
RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.php HTTP/
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^index.php$ http%2:/// [R=301,L]
##### Redirect index.php to / -- END
##### Redirect www to non-www -- BEGIN
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
##### Redirect www to non-www -- END

##### Rewrite rules to block out some common exploits -- BEGIN
RewriteCond %{QUERY_STRING} proc/self/environ [OR]
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|%3D) [OR]
RewriteCond %{QUERY_STRING} base64_(en|de)code(.*) [OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
##### Rewrite rules to block out some common exploits -- END
##### File injection protection -- BEGIN
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=http:// [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(..//?)+ [OR]
RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=/([a-z0-9_.]//?)+ [NC]
RewriteRule .* - [F]
##### File injection protection -- END

##### Advanced server protection rules exceptions -- BEGIN
RewriteRule ^administrator/components/com_akeeba/restore.php$ - [L]
RewriteRule ^administrator/components/com_admintools/restore.php$ - [L]
RewriteRule ^administrator/components/com_joomlaupdate/restore.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/install/index.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/fields/combo.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/fields/modals/typography.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/typography/typography.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/typography/typography2.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jtreelink/dialogs/initialize.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jtreelink/dialogs/links.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jfilebrowser/core/connector/php/connector.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/index.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/phpthumb/phpThumb.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/view_details.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/view_tiles.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/view_content.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/view_list.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/view_images_large.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/view_images_small.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/file_specs.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/swfupload/upload.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/actions.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/process.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jckexplorer/close.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/ImageManager/manager.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/ImageManager/images.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/ImageManager/thumbs.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/ImageManager/editor.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/ImageManager/editorFrame.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jlink/dialogs/suggest.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jautosave/autosave.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/texttranslate/gotranslate.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/atdckeditor/proxy.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/aspell/spellerpages/server-scripts/spellchecker.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jallvideos/dialogs/event.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jallvideos/dialogs/updatemediatype.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jsimpleimagegallery/dialogs/event.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/articlepreview/index.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/GeSHi/dialogs/dialog.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/jdoclink/params.config$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/imageresize/imageresize.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/imageresize/simpleimage.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/htmlfilters/ajaxfilters.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/htmlfilters/helper/helper.php$ - [L]
RewriteRule ^plugins/editors/jckeditor/plugins/uicolor/dialogs/uicolor.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !(.php)$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^plugins/editors/jckeditor/install/ - [L]
RewriteRule ^templates/your_template_name_here/ - [L]
##### Advanced server protection rules exceptions -- END

##### Advanced server protection -- BEGIN

RewriteCond %{QUERY_STRING} =PHP[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12} [NC]
RewriteRule .* - [F]
## Disallow access to htaccess.txt, php.ini and configuration.php-dist
RewriteRule ^(htaccess.txt|configuration.php-dist|php.ini)$ - [F]
##### Advanced server protection -- END

##### Joomla! core SEF Section -- BEGIN
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
##### Joomla! core SEF Section -- END

Blog .htacess contents:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule ^([0-9]{4}/[0-9]{2}/.*)$ /blog/$1 [L,R]
</IfModule>

# END WordPress

Related posts

1 comment

  1. Insert this rule as the first rule just below RewriteEngine line in root .htaccess:

    RewriteRule ^(d{4}/d{2}/.+)$ /blog/$1 [L,NC,R=301]
    

Comments are closed.