After migrating ta large static site to wordpress (as well as a reconstruction), I have a permalink structure that differs from the original directory structure, yet the new post slugs are the same as the original filenames. It's also worth mentioning that the permalink structure mimics the file extension of the old file path.
For example:
what was once (static directory)
www.example.com/old/path/file.htm
is now (wordpress permalink structure)
www.example.com/new/path/file.htm (note: permalink structure mimics the .htm extension)
My question: Is there a simple htaccess rewrite rule that can redirect visitors from /path/to/file/(file.htm) to /new/path/to/(file.htm), without having to create a redirect for each file?
Using mod_alias is even easier:
Redirect 301 /old /new
But if you have rewrite rules in your htaccess file already, then you need to stick with using mod_rewrite:
RewriteRule ^old/(.*)$ /new/$1 [L,R=301]
Related
I need/want to redirect 404 from a specific sub-folder to another page. I am using WordPress. I suspect this would likely be done using .htaccess. I am really struggling with the code. For example...
I would like www.mydomain.com/knowledge-base/url-does-not-exist/ to redirect to www.mydomain.com/knowledge-base/.
Any 404 that is not associated with the sub-folder "knowledge-base" should use the default 404 page set out in WordPress.
I should note that the sub-folder "knowledge-bsae" doesn't actually exist - it is virtual.
Can someone help me with the code?
you could try to insert RewriteRule ^subdirectory/(.*)$ /anotherdirectory/$1 [R=301,NC,L] to .htaccess , make sure there's RewriteEngine On, and paste the code below it.
this reference might help you redirect directory to another
301 is permanent and 302 is temporary for redirect.
another option is, ( i haven't tried this yet ) but you could add another .htaccess file to your subfolder, then ErrorDocument 404 /path/to/yourcustompage .
good luck
I am trying to understand regex URL rewrites and redirects.
I need the following:
www.mydomain.com/tag/*/index.html (for example, mydomain.com/tag/winter-holidays/index.html or mydomain.com/tag/summer-holidays/index.html) to redirect to: www.mydomain.com/index.php/tag/WHATEVER/index.html
www.mydomain.com/*/ (for example, www.mydomain.com/four-roots-of-happy-living/, www.mydomain.com/four-roots-of-happy-living (without the ending slash), www.mydomain.com/living/, www.mydomain.com/living (without the ending slash) AND ALSO www.mydomain.com/category/happiness/ and www.mydomain.com/category/happiness (without the ending slash) to redirect to www.mydomain.com/index.php/WHATEVER/ or www.mydomain.com/index.php/WHATEVER/ WHATEVER/.
I have tried so many different combinations in my .htaccess file that my head is spinning now.
In my .htaccess (currently) I had this, but have deactivated it for the meantime until I can get this straight:
Redirect 301 /* /index.php/*
RedirectMatch 301 /*(.*)/? /index.php/$1
Note: My htaccess file was/is in my root directory, my WordPress site is in a wp folder off that, and it did not have a .htaccess file.
I need to change the display URL from
www.site.com/blog/events/
to
www.site.com/events/
I have installed WordPress in
/blog/ directory and have installed a plug-in for /events/ for dynamic event management.
Basically, I want to get rid of /blog in the URL when /events/ occurs in the URL.
I have tried various rewrite rules using .htaccess file but none of the rules worked out.
Also, there are 2 .htaccess files (the first .htaccess file is the default file found in the root path of the web server and the other is the default WordPress .htaccess file presents inside /blog/ directory).
I am little confused on which .htaccess file I need to try the URL mod rewrite rule.
How to do this using URL mod rewrite conditional rule?
Please help me to see the light. Any support would be greatly appreciated!
Thanks in advance...
Try this code in htaccess root directory :
RewriteEngine On
RewriteRule ^events/(.*)$ /blog/events/$1
The first line allows you to rewrite url. The second line check if the url begin with "events/", and if it's the case, the server is going to look files in the real "blog/events/" directorie.
I have a wordpress site with its own .htaccess automatically generated (because I'm using permalinks), than, my web-admin has configured apache to redirect any third level domain to my site, ie :
http://lol.example.com redirects to http://example.com
and than .htaccess with permalinks rules does the rest.
Now I want to write a rule in the .htaccess file that, when a user types a specific third level domain, redirects to a specific subfolder of my site, ie:
http://sprock.example.com/ redirects to http://example.com/mysprockfolder/
I know my question might sound weird, but I've never done this before so I'm quite confused.
Solved with that regex in my .htaccess:
Right before this comment (just in case you have WordPress installed):
# BEGIN WordPress
I've added the following:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?thirdlev\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/myfolder/ [R=302,L]
with a 302 redirect, everything is good!
it would be much easier for you to just go to your ftp manager and make a subdomain forward to a link. Or, you can make a redirect using php.
when redirecting make sure to add the http://www. or it will think you want to redirect to a part of your page on the site, also make sure that your subdomain has its own folder with its own files and images.
I had old wordpress blog which was under mywebsite.com/wordpress
Now I have moved this blog but I would like to redirect the entire wordpress folder to a single category page mywebsite.com/category/test
The problem is that I don't know how to redirect dynamic pages (all at once) such as
wordpress/?p=1
wordpress/?p=2
wordrpess/?page_id=1362
and others.
I don't need a page to page redirect, just an entire redirect from the wordpress folder to one single category page.
I see that you have used the .htaccess tag, so assume you have access to an .htaccess file.
Try this in .htaccess in the root of your website:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite\.com$
RewriteRule ^facts/(.*)$ http://mywebsite.com/category/test/ [R=permanent,L]
Let us know if that works!
EDIT: Add a ? to the end of the destination rule to strip the querystring info:
RewriteRule ^facts/(.*)$ http://mywebsite.com/category/test/? [R=permanent,L]
Ben
I'm pretty sure that there's an option under dashboard-->settings-->general (maybe?) that allows you to designate your landing page! and that should redirect your site to that category page....
In .htacess file To redirect the page
Redirect /themes_name/your_file.php /themes_name/your_file.php
First your old blog file path and second new blog file path