Wordpress URL rewrites on NGINX server (without htaccess) - php

I've recently learned that I'm unable to use the .htaccess file to redirect and rewrite url's on an NGINX server. I'm in the process of migrating a 20,000 page .html website to wordpress, and must preserve the permalink structure and add redirects to maintain the SEO.
All I am trying to accomplish are two things:
Add a 301 redirect to .html pages that will point them to their .php counterparts
Remove the '/public_html/' folder from the page URL
www.website.com/public_html/[affiliate] => www.website.com/[affiliate]
I have been able to implement the 301 redirects via plugin for now, however I'm unsure how to go about removing the folder from the URL. I could place the affiliate folders in the root directory and not have to do this, but it will clutter up my workspace immensely.
This is my current attempt at rewriting the url (in site.conf.hbs --- is this the correct file?)
#
# Rewrite public_html out of url when visiting affiliate pages
#
location /public_html
{
rewrite ^(/public_html/.*)/(\w+).php /$2.php last;
}
Any help is much appreciated! The php redirect is working via plugin for now, but I'd like to just add it as a rule to get rid of the plugin if possible.
Thanks!

Related

Url redirection for custom post types - wordpress

So i have created a plugin that gets data from a API and creates posts. For example posts urls are similar to following structure .
https://sitesite.net/invite/username
About 100 posts are created this way and the only thing differs is the username. I want to redirect all
urls with /invite to a certain another url.
What is the best way to do this? Please consider that i'm new to wordpress.
So far i've tried some plugins like Redirection plugin and SEO Redirection Premium plugins. But i could not find a way to redirect all the urls with /invite in the url to another url. Both these plugins can set the source url and redirect to another url. But it's not practical for me as i have 100s of urls.
How can i redirect all my urls to another url .
The best way is to do it directly in your .htaccess file in the root folder of your Wordpress installation.
The following rewrite rule will redirect all pages in your invite folder to the same page in another folder called newfolder:
RewriteRule ^invite/(.*)$ /newfolder/$1 [R=302,NC,L]
Note the R=302 - make sure you use this for testing and only change it to a permanent 301 redirect when you are sure everything works!
(The .htaccess is not a Wordpress file, standard file on your web hosting. But if you’re not familiar with it, it’s a very important file to make your site work, so check back with us if you’re unsure of anything before you change it and always make a backup before ANY changes to it!!)

Rewrite URL only wothout redirecting the page

I have a wordpress site installed on a domain, inside a subfolder. Now my client wants to show it as the default page, but I don't know how to do it without reinstalling WP to the root directory of the server.
I simply want to rewrite to URL of mysite.com/wp to mysite.com, and other subfolderls like mysite.com/wp/a-wordpress-page to mysite.com/a-wordpress-page
What I've tried so far:
Placed an index.php to the root with header redirect, but it will rewrite the URL to /wp
Including the /wp/index.php to the main index.php. It works when you open the page, but after following any link on the site, the /wp/ part will show up again.
Tried some RewriteRules in .htaccess but can't figure out how to do it correctly.
So what is the easiest solution to do it with .htaccess or PHP?

Ultimate SEO Module + htaccess 301 .html redirect issue

I have successfully installed the Ultimate_SEO_URLs_v2.103 to my shopping cart installation (which is v1.36).
We are getting ready to go live with the site but I need to redirect html pages that are indexed by google to the new html page names.
The problem that I am having is trying to redirect pages with .html extensions to the page names that are rewritten by the htaccess file fromUltimate SEO URL.
It works if I use .htm page for the original page and redirect to the new counterpart page.
Here is the code I am using in .htaccess file (after Ultimate SEO rewrite code):
redirect 301 /old_conditions.html domain.com/conditions.html
so if you go to http://domain.com/old_conditions.html I want it to redirect to http://domain.com/conditions.html
It doesn't work, it goes to the page can not be found page!
Can someone please help me figure out why I can't get a redirect from a .html page when using the Ultimate SEO URL module?
Thanks in Advance!
You can use this rule in your root .htaccess using RewriteRule directive:
RewriteRule ^44-wholesale-celosia\.html$ /flowers/celosia.html [L,NC,R=301]
Also make sure this rule is right at top just below RewriteBase / line.

Alias within htaccess, and block access to original file? (URL rewriting)

I have a very basic two-page website: the home page, and an about page. What I'm trying to do is use htaccess to rewrite the URLs so that the appear as:
domain.com/ (for the home page)
domain.com/about (for the about page)
In the actual folder structure of the site, the homepage is /index.php and the about page is /about.php (both appear in root).
I've been doing research into using alias but unfortunately my hosting (Dreamhost) doesn't allow access to httpd.config so that's out the window and I'm left with using rewrite rules in the htaccess file.
Since the index.php file will appear in the domain root (http://domain.com/) automatically, I've so far managed to make the about page appear correctly at domain.com/about using these lines:
RewriteEngine On
RewriteRule ^about$ /about.php
I'm also using 301 redirects so that for example, domain.com/about/ (with the trailing slash) also directs back to the /about URL like this:
Redirect 301 /about/ http://domain.com/about
This works great.
However the index.php and about.php files still also show if you go to the correct URL within your browser (eg: domain.com/about.php) so as a result the search engines are seeing (and indexing) two versions of each page! I've set up the correct canonical metadata within each page but this doesn't seem to have had any effect (the canonical metadata have been within the page markup ever since the site went live).
So how would I go about firstly doing a 'blind' rewrite (for want of a more technical term) for the two files so that the URLs look correct, but also effectivly 'block' direct access to the files - ensuring that if someone were to attempt to access the php files directly, the URL would still appear in the visitor's browser as the 'pretty' versions rather than the full file name and php extension?
Any advise would be hugely appreciated, I've been researching this for another couple of days now (I don't think there's anything quite the same as this anywhere on here already) and cannot for the life of me work this one out!
Check $_SERVER['REQUEST_URI'] in the PHP files. If that contains the filename (instead of the URI that you want), then do a 301 or 404 or whatever you want. Else serve the page as usual.
You can also do a
RewriteRule ^about.php - [L,gone]
or
RewriteRule ^about.php /about [L,R=301]
but this has to go before your other RewriteRules. It will send a 410 Gone or a 301 Moved Permanently response if the page is accessed via /about.php. See Apache Module mod_rewrite for the complete documentation of mod_rewrite.

Using self hosted Wordpress with a 301 redirect

Recently I've been working to develop a multi-user Wordpress site with Wordpress 3.0 however at the moment we are iso.g one server to showcase preview static content in a subdirectory while multi WP is in the root directory.
My question however is how to keep the root directory hidden from the publc. Curntly I have a PHP index file handling he redirect howevwer as WP has its own index file I waned to ask about any possible alternatives.
Thanks very much for any assistance,
You're probably going to want to do it with an .htaccess file. However, Wordpress has one of those too, so rename the current .htaccess file to .htaccess.orig (or whatever you want... but don't delete it) and then create your new .htaccess file with your 301 redirect.
Then whenever you are done, just rename everything back to the way it was.

Categories