Multiple RewriteEngine calls, or another way to solve this problem? - wordpress

I have Wordpress multisite installed at the root of my site (the Wordpress files are actually in /wp, but it's configured so that each subsite URL is at the root - eg. /site1, /site2 etc.) This means that there's a Wordpress section in my .htaccess file that I probably shouldn't be touching, because Wordpress might overwrite those changes.
However! There is a redirect I would like to build, from (say) /path/to/oldsite to :8080/newsite, and I don't know how to do this without RewriteEngine. Other redirects I have managed to do basic 301s with, but I don't know how to redirect to a different port that way. My test attempt to have multiple sections that use RewriteEngine didn't work since apparently only the final RewriteEngine section gets heeded?
Anyway, that's my issue. Any suggestions for the best way of building this redirect? Am I just going to have to create empty directory /path/to/oldsite to put a redirect in?
Thanks!

Related

Redirecting specific urls to subfolder on same domain

I have moved my phpBB board from dommain.com to domain.com/forum.
I have launched a Wordpress website on domain.com.
As a consequence, all links to topics on my board end up on a 404 page of my Wordpress website on domain.com
I would like to redirect links to topics on my board.
For example:
Redirect: example.com/viewtopic.php?f=17&t=35
To: example.com/forum/viewtopic.php?f=17&t=35
So only /forum should be added.
Is changing the .htaccess file of my WordPress website the best way to do this? And if so, what would be the correct code?
Of are there better ways (faster/better for SEO) that I don't know of.
Is changing the htaccess file of my Wordpress website the best way to do this?
Implementing this in the root .htaccess file is a reasonable way to do this, unless you have access to the main server config. Alternatively, you could perform this redirect in PHP (in WordPress), but that puts the burden on your WordPress site.
For example, at the top of your root .htaccess file, before the existing WordPress directives (ie. before # BEGIN WordPress) try the following:
# Redirect old forum topics to "/forum" subdirectory
RewriteRule ^viewtopic\.php$ /forum/$0 [R=301,L]
Any query string is passed through by default. So, a request for /viewtopic.php?<something> is redirected to /forum/viewtopic.php?<something>.
The $0 backreference contains the URL-path matched by the entire RewriteRule pattern. ie. "viewtopic.php" (this simply saves repetition).
NB: You should test first with a 302 (temporary) redirect to avoid potential caching issues.

WordPress will not force SSL for the life of me

Hate to complain but I've spent like 2-3 hours working on trying to secure my WordPress site via SSL. I can successfully browse to my site via HTTPS, but I always get mixed content. I've tried several plugins, but there are still resources that are pulling images via HTTP. If I tried to browse to the URLs of those images manually, my web browser actually switches the URL to HTTPS, so I'm not sure why the site loads the images under HTTP but browsing to the images manually forces it over HTTPS. Very Confusing.
I've tried adding this in the .htaccess file of my root directory, so that all requests to the subdirectory /wp-content/ are forced over HTTPS, but it still does not work:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(wp-content/.*)$ https://www.example.com/$1 [R=301,L]
When I add this into the .htaccess file, reload the site, inspect element, I still see numerous links in here with http.
I've also tried HTTPS Easy Redirection, which forces HTTPS on everything but then results in a redirect loop. Still no luck.
Any suggestions would be greatly appreciated. It seems to just be the images.
What you have setup so far works, but does not address the root issue. As a matter of fact the .htaccess redirect is overkill.
Your Wordpress configuration needs to be edited. Go to your settings>general, ensure that the Wordpress Address Url and Site Address Url are https. It's that simple. You also need to edit any hard coded content urls to https.
You could use some wacky plugin to mutate your links but I would not advise it. But it won't work all the time. That will depend on how your content is constructed.
If you want to play it safe, whenever your add a resource link to content simply omit the protocol like this: ://example.com/.... That scenario works well with content generated by Visual Composer and the likes.
If the SSL is successfully installed in your server then use this plgin: https://wordpress.org/plugins/really-simple-ssl/
This will works for you...
Note: Take backup of your website and database first then proceed with the above plugin.
Thanks

Replace all URL's for my WordPress site using a different domain name?

The domain names used are only examples, so if you could use those example names in your answer that would be great. I'm having a very hard time wording exactly what I'm trying to do and because of that can't find the answer via searching, so I'm posting it as this analogy:
I work for a company that makes WordPress sites. We'll call that company SuperMedia, and their main website is supermedia.com. SuperMedia wants to host their clients' sites on their own server via subfolders. So in this case, we've created a client's WordPress site in the directory http://supermedia.com/greatclient/
The issue is that our client has a domain name, friendlyclient.com, and we need to link this domain name to their site which we are hosting on our server, but we don't want the urls to show "supermedia" at all.
So in simplest terms, right now all of our page urls look like this:
http://supermedia.com/greatclient/about
http://supermedia.com/greatclient/our-services
http://supermedia.com/greatclient/gallery
(etc...)
But we want them all to say:
http://friendlyclient.com/about
http://friendlyclient.com/our-services
http://friendlyclient.com/gallery
(etc...)
but still display the information on http://supermedia.com/greatclient/about, http://supermedia.com/greatclient/our-services, http://supermedia.com/greatclient/gallery, etc. respectively.
Is there a simple, fairly fast way to do this for all the pages we've created, either using .htaccess or some kind of plugin? I don't have a lot of back-end programming/database knowledge, so if it involves advanced programming, could you lay-out some steps on how I can achieve this?
If you are using apache, you can use mod_rewrite to do the rewriting. Try adding this to your .htaccess file(In the friendlyclient.com root folder)
# Match the host
RewriteCond %{HTTP_HOST} ^([^\.]+)\.com$ [NC]
# proxy the entire request to the /host/ and path
RewriteRule ^(.*)$ http://www.supermedia.com/%1/$1 [L,P]
This will make it so requesting http://friendly.com/about will serve http://www.supermedia.com/friendlyclient/about and dont forget to rename ur folder, from greatclient to friedlyclient

How to tackle existing url's when moving from Joomla to Drupal site

I've a Joomla site but I want to move it to Drupal-6 site. How should I go about changing existing url's? Should I add the redirection in .htacces or use any redirect modules?
One main reason of moving is the forum module in Drupal which I'd like to use.
I'd be using nodealias & global redirect modules.
In my site I'm using SH404SEF to generate urls(with .html suffix).
You can absolutely place a redirect in the .htaccess file and reference the pathauto generated path.
http://drupal.org/project/pathauto generates URL aliases based on title etc. and then put something like:
RewriteRule ^misc/about.html http://www.example.com/aboutus/ [R=301,L]
for each URL. (This is better off in your apache httpd.conf file for performance reasons.)
Or there is a module:
http://drupal.org/project/path_redirect
Which looks like it does just what you want but I've not tried it.

Cannot find .htaccess, can I create one? What else can I use to redirect html pages to blog posts

I have a website and want to redirect all its pages to posts on my blog. I browsed through my website folder but could not find the '.htaccess' file. Is it provided by the web hosting or can I create my own and use it? Can it be only used with Apache server.
If that's not possible what other option do I have for redirection.
Janice
You create your own .htaccess, by simply opening a document and saving it as .htaccess.
You'll want something like this in it:
RewriteEngine on
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
Perhaps you just don't see the .htacces file. The dot at the beginning of the file name indicates that this is a hidden file and will not be displayed normally.
If you don't want to mess around with editing your .htaccess file, Redirection is a good Wordpress plugin that handles 301 redirects, logs, etc. and is easy to use.
.htaccess is for Apache only, other web servers have their own methods of configuration and do not use .htaccess files.
Since this is tagged "Wordpress" maybe you are using that? Wordpress will create one after you've turn on pretty permalinks.

Resources