php - WordPress Redirection not working after Moving to Subdirectory -


today moved wordpress website root directory subdirectory in same domain. moved files new subdirectory. have setup 301 wildcard redirection hosting cpanel

301 wildcard redirection setting -

old address - https://www.example.com

new address - https://www.example.com/blog/

when visiting post directly https://www.example.com/blog/this-is-a-post showing correct post without error problem when opening same post without "blog" word i.e. https://www.example.com/this-is-a-post showing correct post instead of redirecting https://www.example.com/blog/this-is-a-post.

and when visit through google visiting old address i.e. without word "blog".

one more thing occuring redirecting https://www.example.com https://www.example.com/blog don't want because have different html index file homepage

url settings in wordpress dashboard -

wordpress address (url) - https://www.example.com/blog

site address (url) - https://www.example.com/blog

contents of .htaccess file:

# begin wordpress <ifmodule mod_rewrite.c> rewriteengine on rewritebase /blog/ rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /blog/index.php [l] </ifmodule>  # end wordpress 

after removal of .htaccess , index.php file of wordpress root directory , removal of 301 redirect cpanel.. problem fixed. have different welcome page in roodex.com , have wordpress blog in roodex,com/blog but problem when visit through google search result google showing old post url links , after visiting through showing "not found" instead of redirecting new url.

assuming serving static files root of site (ie. don't have virtual urls , front controller wordpress) best can redirect request root directory (outside of /blog) not map physical file, /blog subdirectory , hope best. if url doesn't exist within wordpress either you'll wordpress's 404 page.

i assume have .htaccess file in /blog subdirectory handles wordpress requests?

so, in .htaccess file in root of site (which believe empty), try following:

rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule !blog/ /blog%{request_uri} [r=302,l] 

change 302 (temporary) redirect 301 (permanent) when sure working ok. 301s cached hard browser can making testing problematic.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -