Apache Rewrite Condition After Upgrade - apache

We recently upgraded a system and have noticed that our URLs have changed. I would like to configure our Apache web server so that it permanently detects the old URL and redirects users to the new URL.
All URL parameters have remained unchanged apart from one, see below;
Old URLs;
https://example.com/products/cat_one/record/1656782?lang=eng&type=grey
https://example.com/products/cat_one/record/1188746?lang=eng&type=blue
https://example.com/products/cat_one/record/4499814?lang=eng&type=black
New URLs;
https://example.com/products/cat/record/1656782?lang=eng&type=grey
https://example.com/products/cat/record/1188746?lang=eng&type=blue
https://example.com/products/cat/record/4499814?lang=eng&type=black
As you can see, the cat_one parameter has changed to cat.
We've been told by the supplier that this kind of redirect isn't possible and it's our responsibility to update all old URLs manually, surely this isn't correct?
How can I achieve this, wither via htaccess, vhosts file, or similar - I've seen various ways to achieve this. I think I require a 301 redirect / rewrite rule?

Related

Is there an Apache/Plesk server setting that governs https:// behavior?

Context:
I've recently moved a site to a new host, and moved the SSL certificate from the old host to the new one. The code, written in PHP, is a big mess made by someone no longer available many years ago. Because of this, I'm hoping to figure out something related to the configuration of the server that can fix the issue so I don't have to reverse-engineer the rather messy code.
Problem:
When users navigate to an area of the site that uses https://, all goes according to plan. The problem, however, arises when they click a link in the navigation that is normally to an http:// part of the site. On hover, you can see that the target URL incorrectly includes "https://". When the user tries to go to a non-secure area with https:// in front, either by clicking one of those altered links or by typing it into the location bar of the browser, they are redirected to the directory without any domain. For example, if you try to go to "https://domain.org/site/", the browser is redirected to only "/site", which of course cannot be found.
Theoretical solutions:
Is there a setting in Plesk which governs the "stickiness" of https? One way to fix the problem is to stop the non-secure links from acquiring https://.
Is there an obvious reason why whatever script or file the site is using to redirect would break when an un-secure area is accessed via https://? Is there a server setting that would have made this function differently on the new server via the old server?
I don't have access to see what exactly the configuration of the old server was. Is it likely that this could be caused by a difference in PHP version? If so, any suspicions about what the problem would be?
Is there some workaround with .htaccess that can manually redirect all but certain secure areas of the site to http:// when they are accessed via https://, presumably before the site's redirect script is activated?
Thank you for any help!!
Yes, since Plesk 17 (Onyx):
For older versions you can create .htaccess files which will rewrite request from https pages to http, based on referrer:
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^https://domain.org [NC]
RewriteRule ^(.*)$ http://domain.org/$1 [L,R=301]

apache keeps old .htaccess settings (in rewriterule)

I am testing some basic .htaccess rewriterules and I am pretty sure that even after deleting a rule in .htaccess and saving the document, apache ignores it and acts like the rule was still there (only for earlier requested sites) - even after apache restart. It is driving me crazy, the behavior is really mad. Is there any apache cache which is about to be cleaned or the problem is elsewhere?
It's madness! Not really, it's just annoying.
When you set a redirect in Apache what you're doing is actually configuring headers that are passed to your browser. Your browser keeps a cache of 301 and 302 redirect headers (and other things like DNS) in the event you go back to those pages, so it can save you time. 301 redirects are supposed to be permanent (that's what you're indicating), so if there is no need for the browser to do something like perform a DNS lookup or visit a page based on a redirect, then it will cut corners and use the cache in order to provide you with a faster browsing experience.
You need to flush your browser's cache to prevent the store redirects from happening.
Additionally, you'll want to resubmit your page to Google (in the event it's on the web) in case they've crawled your site while the invalid headers existed.

mod_rewrite - Does Apache caches .htaccess rules? (still follow rules even after deleting the .htaccess file)

I was doing some tests with mod_rewrite in my wamp environment.
I tested a simple rule that I put at the root of one of my websites and asked it to redirect any request ending with index.php to localhost (there is no sense to it, just wanted to check the rule)
It worked, but after, any change I'd made to my .htaccess file rule was not reflected.
After a while I just decided to delete the .htaccess... well it's still doing redirection! I just don't understand it. Does Apache cache the rules or something (restarting services trough wamp menu didn't change anything)
(Don't ask for the exact rule I used, since I deleted the file, I don't think it's relevant anyway)
.htaccess files are processed each time a request comes through. It is possible that your browser cached the request being forwarded. Did you try it with httpfox or anything to see what the headers said?
Have you tried deleting the browser cache?

How do I rewrite URLs with Nginx admin / Apache / Wordpress

I have the following URL format:
www.example.com/members/admin/projects/?projectid=41
And I would like to rewrite them to the following format:
www.example.com/avits/projectname/
Project names do not have to be unique when a user creates them therefore I will be checking for an existing name and appending an integer to the end of the project name if a project of the same name already exists. e.g. example.project, example.project1, example.project2 etc.
I am happy setting up the GET request to query the database by project name however I am having huge problems setting up these pretty url's.
I am using Apache with Nginx Admin installed which mens that all static content is served via Nginx without the overhead of apache.
I am totally confused as to whether I should be employing an nginx rewrite rule in my nginx.conf file or standard rewrites in my .htaccess file.
To confuse matters further although this is a rather large custom appliction it is build on top of a wordpress backbone for easy blogging functionality meaning that I also have the built in wordpress rewrite module at my disposal.
I have tried all three methods with absolutely no success. I have read a lot on the matter but simply cannot seem to get anything to work. I am certain this is purely down to a complete lack of understanding on with regards to URL rewriting. Combined with the fact that I don't know which type of rewriting should be applicable in my case means that I am doing nothing more than going round in circles.
Can anyone clear up this matter for me and explain how to rewrite my URLs in the manner described above?
Many thanks.
If you are proxying all the non static file requests to Apache, do the rewrites there - you don't need to do anything on nginx as it will just pass the requests to the back end.
The problem with what you are proposing is that it's not actually a rewrite, a rewrite is taking the first URL and just changing it around or moving the user to another location.
What you need actually takes logic to extrapolate the project name from the project ID.
For example you can rewrite:
www.example.com/members/admin/projects/?projectid=41
To:
www.example.com/avits/41/
Fairly easily, but can you map that /41/ in your app code to change it to /projectname/ - because a URL rewrite can't do that.

Changing site URLs in Joomla with Apache mod rewrite

So I'm trying to clean up the URLs on my site, and have digged around for information here and not figured out why I'm still getting errors.
Basically, I have a site that revolves around a search engine, and once the user sees the results and clicks on one, it goes to a URL that looks like:
www.mysearch.com/searchresults/204982398sjfdkf&thisismorejunk=junkjunk=1331
Well, sort of, but you get the point.
I want to clean this up for each result, so it looks like
www.mysearch.com/searchresult1001
I'm using the Joomla platform on my backend, and enabled 'Search Friendly URLs' and there was no problem (although it did almost nothing for me). Then before I enabled 'Use APACHE mod rewrite' I put the following code into my .htaccess file
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^Joomla161_2/joomla\.html http://www.joomla.org/? [R=301,L]
(The last rule was just to see if the rewrite rule works, which it does)
First problem - My host automatically overrides the Options command, saying I can't do it for security reasons - but I figure maybe this isn't big because the rewrite rule still works.
But then when I try to enable 'Use Apache rewrite' my whole site breaks. Worse yet, I have no idea what to do next to actually CHANGE the URLs of my search results.
Options +FollowSymLinks
It is very possible that your host has this enabled by default and
adding to your .htaccess file is causing a conflict.
If your mod-rewrites are working without it then there is no reason
to add it.
Joomla Apache Rewrite
Change the seo settings and htaccess back to default setting.
BEFORE! you change any of the options in the Joomla admin for seo friendly url's or Apache rewrite you must FIRST! rename your htaccess.txt to .htaccess
In some cases you may have to give the server a min or two to notice it.
Now change the Joomla admin settings to seo friendly and enable rewrite.
Search Rewrite
If the above setting are configured correctly then your websites search results will have landing pages with nice urls.