I am planning on migrating a blog that is currently hosted at
www.blog.com
to a subdirectory in a new domain such as
newdomain.com/blog
So far I've seen several tips on how doing this and [in particular from Yoast (Joost) is helpful but not identical to my situation 1.
Any suggestions?
The main steps on Joost's article are as follows:
[1 ] Edit wp-config.php
define('WP_SITEURL', 'http://www.newdomain.com');
define('WP_HOME', 'http://www.newdomain.com');
[2 ] Use the Search and Replace plugin to replace old URLs
[3 ] Update .htaccess to
Redirect 301 /blog/ http://www.newdomain.com/ // <== note this is NOT my situation
// I likely need the reverse
However, this won't address my particular need, in which a different change in .htaccess and wp-config.php may be necessary.
Any suggestions?
Wordpress has some RewriteRules that it wants to use in an .htaccess file. It should look something like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I think that all you need to do is take this and place it in an .htaccess file in your document root (where http://www.newdomain.com/ is). If you don't have any special rewrite rules or options in your .htaccess file, you could just move the file out of /blog/ and into /. You don't want these rules in both places.
Then in wordpress' admin panel (you'll need to go here: http://www.newdomain.com/blog/wp-admin/options-general.php ) there are 2 fields, one for WordPress address (URL) (this should say http://www.newdomain.com/blog/ ) and one for Site address (URL) (this should say http://www.newdomain.com/ ). And I think that's all you need to do.
If you are using custom themes you may want to double check any absolute URIs you have in the headers/footers/etc.
There's some more information about doing this here: Giving Wordpress It's Own Directory
EDIT: I forgot to mention that you need to create an index.php in your document root. In the link above, under the section Using a pre-existing subdirectory install, you need to follow the steps to create an index.php. You only need 2 lines.
As for the code-igniter/wordpress conflict. You may need to get the 2 rules to jive with each other, and that may not be so easy to do. You either have to move code-igniter's rules into their own directory or use RewriteCond to make sure they don't step on each other. For example, adding a RewriteCond !/index.php so wordpress' rewritten URI won't get re-rewritten by code-igniter's.
I would suggest a clean install. Just export your blog posts as XML, and copy over the uploads.
Related
I have a WordPress Multisite installation here: mydomain.com
I use it to have different languages like:
mydomain.com/fr
mydomain.com/de
...
Now we are changing design, but we would like to do step by step, language by language.
So we have installed another Wordpress Multisite in the folder /new, that it's working perfectly with sites like
mydomain.com/new/fr
mydomain.com/new/de
...
We would like to redirect JUST THE FRENCH language to the new wordpress. I've tried with this .htaccess in the root folder (based on the information in Wordpress documentation:
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteCond %{REQUEST_URI} !^/fr/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^fr(.*)$ /new/fr/$1
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^fr(/)?$ /new/fr/index.php [L]
But that is giving a "Error establishing a database connection". It's weird because, as I explained, the site mydomain.com/new/fr is working perfectly.
NOTE: we don't want to use subdomains, I know that would make a different approach and solution ;-)
EDIT: The error is because this query
SELECT blog_id FROM wp_blogs WHERE domain IN ( 'mydomain.com' ) AND path IN ( '/fr/', '/' ) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1
I guess, the redirection is working well, but when the wordpress inside "new" directory tries to determine which blog to visit, it reads the URL and it's in "/" really, since the redirection rule has an [L] and keeps the original URL in the apache environment variables.
If you activated Multisite on WordPress 3.5 or later, you can follow the documentation setup in the section .htaccess and Mod Rewrite
According to the documentation:
.htaccess and Mod Rewrite Unlike Single Site WordPress, which can work
with "ugly" Permalinks and thus does not need Mod Rewrite, MultiSite
requires its use to format URLs for your subsites. This necessitates
the use of an .htaccess file, the format of which will be slightly
different if you're using SubFolders or SubDomains. The examples below
are the standard .htaccess entries for WordPress SubFolders and
SubDomains, when WordPress is installed in the root folder of your
website. If you have WordPress in its own folder, you will need to
change the value for RewriteBase appropriately.
I've recently relocated a WordPress site to a new host. I followed the instructions from here and things seemed to go ok. However on the old host the installation was inside a sub-folder (news). On the new host I want it in the public_html folder. All files are up, I have made the appropriate changes to the wp_config file, I have edited the .htaccess file and removed any references to the old path, I have even gone into the wp_options table and made the url changes there.
However for some reason whenever I reference the index.php, it tries to point back to the old sub-folder location. I've looked in the wp-settings, wp-load files etc and for the life of me cannot find where the bad path information is.
I've gone to the wordpress.org site and several other sites, any help would be appreciated.
UPDATE: I deleted my wp_config file and the system asked me to setup, so I did. During the setup it recognized that the database was there, etc, and sent me to the login. I was able to login, looked at the settings, etc and they are all as they are supposed to be.
If I go directly to wp-admin or wp-login it lets me log in with no problem. however when I try to go to the site, nothing, however instead of showing the old url, it now shows a blank screen.
Thanks
First of all make sure that your whole database does not contain any references to the old installation otherwise some redirection may be active. For migrating your database nowadays you use the following tool to make sure that also serialized data does not contain any references to the old URL:
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
Can you reach your backend? If only the frontend does not work its probably a permalink problem update your permalinks by going to Settings -> Permalinks -> Save (Update)
Check your index.php and the index.php file from the main directory and also from the subdirectory if there any redirection is active
Do a search (and replace) for the content of all files within your WordPress installation and check for any possible hardcoded redirection
It MUST be one of those problems.
If still no success debug your WordPress installation step-by-step (with echo "reached"; die;) to find out WHEN the redirection is happening - important points to check:
index.php file
wp-config.php file
Action Hook 'init'
Action Hook 'template_redirect'
This might also be helpful: http://rachievee.com/the-wordpress-hooks-firing-sequence/
Check your .htaccess file.
You probably have something that looks like this(notice the subfolder):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subfolder/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subfolder/index.php [L]
</IfModule>
# END WordPress
When you should actually have something that looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
First although neither of the two posted answers solved the problem, they both were instrumental in helping me figure out what was wrong, so I voted each of them up.
Since I could log into the admin area, I knew things were pointing to the correct place. But I was still getting a blank page, well it turns out that somehow in the ftp transfer of the backup site to the server, the 'themes' folder didn't make it. Once I uploaded that folder, things are close to being back to normal.
Again, the advice I received helped me tremendously in troubleshooting this sucker. Thanks
I want to make a better link shortener service using YOURLS. I've procured a short URL for this: sly.pe. YOURLS is installed and sly.pe/admin is accessible.
I'd also like to use WordPress to power most of the consumer facing site, at the URL: sly.pe. The idea being I want users to register for the site using WordPress and a registration plugin like OneAll social. Once authenticated they get logged in for both YOURLS and WordPress and are redirected to a URL like sly.pe/home that uses WordPress as the site but YOURLS (sly.pe/admin for that user) is embedded and accessible somehow.
Both services make .htaccess changes. If I leave the file as is, I can't seem to have any other WordPress URL other than sly.pe, but YOURLS works fine. If I comment out some YOURLS code, WordPress can use other directories, but then YOURLS doesn't work. How can I have both coexist nicely? Or at least define the WordPress URLs I want and get those working?
(commenting out the YOURLS code gets WordPress working, but breaks YOURLS):
.htaccess:
# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
</IfModule>
# END YOURLS
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I was able to get YOURLS to work with WordPress. Here's how I did it...
I've placed YOURLS in niemannross.com/links - so for me, a redirect looks like http://niemannross.com/link/rlunchlessons
Install the Redirection plugin by John Godley in your copy of WordPress.
Look in Wordpress:Admin:Tools:Redirection. Across the top are several tabs. You should see Redirects | Groups | Logs | 404s | Import/Export | Options | Support.
Choose Redirects
Select Add New Redirection
Source URL: /link/.* - Select Regex.
Target URL: /link/yourls-loader.php
Group: Whatever makes sense in your setup. I've chosen wordpress:redirections
This works for my installation.
Simple answer is: you cannot. Both WordPress and YOURLS (please, YOURLS, not YourLS) need to process server requests to return the expected result (eg when requesting http://sho.rt/blah, each app needs to check if blah is content it manages)
Long answer: you should not because all of the following.
Basically you would need something that works when:
blah is an WP article but not a YOURLS short URL
blah is a YOURLS short URL but not an WP article
blah is neither a WP article or a YOURLS short URL
optionally decide what to do when blah is both a WP article and a YOURLS short URL
Your code would also need to :
prevent WP to create a "slug" that is already a YOURLS short URL
prevent YOURLS to create a short URL that already matches a WP slug
You'd need to have code for this both in the WP area and in the YOURLS area.
Bottom line: lots of edge cases to deal with. What might work in some case on your side might not work in other cases, on your side or with others.
I think you're going to have to work around the problem as mentioned by #Ozh, but here's a plugin that will make it easier for your WordPress users to use YOURLS: https://wordpress.org/plugins/yourls-link-creator/
You cannot, I tried different ways, maybe with new apache 2.4 using the if else statement you will, but I am not an expert on those commands, I want to share what I did to have the shortener option in the root page and the html site in a subdirectory, with this solution you can still give people normal url for the website (e.g. sho.rt):
set your website in a folder under root with a name e.g. "w", that means it will be at "sho.rt/w"
then use this .htaccess
# BEGIN YOURLS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
RewriteRule ^$ /w [L]
</IfModule>
# END YOURLS
This will give you the option to still use sho.rt as your website address if the user doesn't pass any subfolder in the url, but if they do, it will check in yourls first and go to your folders if nothing found.
One more thing, do not forget to add "w" in the $yourls_reserved_URL array in /user/config.php (Yourls config file)
I finally solved this for my website.
I have a subdomain http://sub.domain where I installed YOURLS, but the short URLs are at http://domain/someshortlink
And the wordpress website is also at http://domain/
It used to work with the swap plugin ( https://github.com/gerbz/Yourls-Swap-Short-Url ).
Just with the htaccess provided by that YOURLS plugin, and no wordpress. But since I decided to move to wordpress, this combination won't work.
Here is the trick:
On your htaccess, keep it simple, as wordpress wants it to be. Remove the snippet htaccess for the YOURLS swap plugin, if you have it added.
Edit your 404.php page theme. Mine was at: wp-content/themes/twentynine/404.php
At the very begin, just add:
<?php
header('Location: http://sub.domain' . $_SERVER['REQUEST_URI'] );
exit;
?>
This will allow:
All files and directories will honor the basic htaccess from which they are simply served
All URLS not files and folders will be handled by wordpress in the usual manner.
If a page is not found, wordpress will trigger 404.php which will send that page to YOURLS to try
If YOURLS also don't find it, a 404 page from YOURLS will show.
Remember to edit the 404 page from YOURLS also, to match your wordpress theme.
Best of luck!
Reference: https://github.com/gerbz/Yourls-Swap-Short-Url/issues/11
I have an issue where we are merging a website with Wordpress. The website has a ton of news stories in a "/news" directory that we need to keep. When we add the CMS at say "/wordpress" we can set the base URL to the root of the directory so when we make a new post in the category "news", the link for it is "/news/this-is-the-post-title", except the REAL location is "/wordpress/news/this-is-the-post-title". So my issue is that we want to keep all news stories at the "/news" URL, and in my head we just need the .htaccess to say "if the requested URL doesn't exist in the /news directory, try /wordpress/news", and of course if Wordpress doesn't find anything, it can 404. Hope this makes sense, thank you!
I don't fully understand how the original news stories are held. But, if they are grabbed with PHP then you should be able to redirect to /wordpress/news/post-title if it doesn't exist.
On the other hand, if the news stories are static files you can check for them with .htaccess and make sure the file exists on the server.
# Goes in the "news" directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /news
# These make sure the file or directory doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Redirect to /wordpress/news/whatever-entered-goes-here
RewriteRule ^(.*)$ /wordpress/news/$1 [L]
</IfModule>
Reference: http://www.addedbytes.com/cheat-sheets/mod_rewrite-cheat-sheet/
If you only use WordPress and static pre-existing directories and files (and not another CMS, next to WordPress), you can probably just follow the directions on giving WordPress its own directory. All WordPress files go to wordpress/, only the index.php and .htaccess are copied back to the root directory. The standard .htaccess from WordPress already has the two RewriteCond rules that check for existing files, so if the request is for news/happy-2010.html and this file already exists, your server will just serve this and not start WordPress.
At various points of the day my WP permalinks keep breaking. When I'm using custom perms it works but then a few times during the day it just throws a Page Not Found. I fix it by setting perms to default, then back to custom and it works fine.
My Sys Admin can't figure it out. Hopefully a guru can lend some help?
The problem is indeed most-likely the sCategory Permalink plug-in (the one that gives you /%scategory%/. 404s are somewhat common. Go to Options | Permalinks page in Site Admin and click Save Changes to regenerate permalinks. They way to confirm this is to use WP-default permalinks to test behavior. If all is working well, it is the sCategory Permalink.
If this isn't working, publish your .htaccess and that will help us troubleshoot better.
I'd be suspicious of something that is periodically overwriting your .htaccess file. When you set the permalink options, it updates .htaccess. If those settings are being "lost", there might be another piece of software running on your site that is mucking with the .htaccess file and removing or overriding the WordPress settings.
It seems that something else is automatically changing your htaccess file and overwriting the permalink settings.
What bvandrunen suggested may work. If not, you could set the permalink settings to what you want and then immediately change the permissions of the htaccess file to prevent anything from modifying it. I would suggest using chmod 644.
Naturally, a better solution still would be to find the script which is modding your htaccess file and get rid of it... but this fix should at least keep your permalinks working!
Do the creation/modification dates of .htaccess change or not? Even if you see no visible changes in .htaccess?
Permlinks are stored in the wp_options table in option_id 34 . Check them and then check after the change takes place.
Delete the existing Permalink structure and set it to default.
Delete the current .htaccess file.
Purge your site cache.
Write a new .htaccess file like #bvandrunen suggested.
Create your new permalink structure again.
That should work.
You can try using the 'try_files' directive in the Nginx configuration file for your website:
a) Open the configuration file present at ‘/etc/nginx/sites-enabled/yoursite.conf’ or ‘/etc/nginx/conf.d/default.conf’
b) Then add the following lines under the location / block:
try_files $uri $uri/ /index.php?$args;
c) It should look like:
location / {
root /var/www/html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
You may also check out WordPress custom permalinks and Nginx for detailed information.
I would have to agree with #ahockley since I had this exact same problem with my WordPress blog. Which is happening is that the .htaccess file is getting overwritten and then when you set it to custom and then back to default it corrects itself for a while. What I had to do was something like this: (this is the default)
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Change to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# BEGIN WordPress
# END WordPress
Once I moved the # BEGIN Wordpress out of the blocks the problem stopped. Hope this helps
.htaccess wasn't uploaded with my build!!!
A stupid mistake in my build process!
You may want to check server limits. We had this issue when MySQL was running out of space. When in your SSH, use
df -h
to list files and see if anything has run out of space