.htaccess rewrite working on 2.4 but not on 2.2 - apache

First an explanation of what I am trying to achieve here: If I share a url on google/facebook and so on, I want them to scrape a different page than what users see.
I have the following rewrite rule defined which works on my local machine running Apache 2.4. (I test this by changing my user agent string)
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet|Google) [NC]
RewriteRule event/(\d*)$ http://example.com/sharepage.php?id=$1 [P,L]
Our public server is running Apache 2.2 though and I keep getting a response of 500 Internal Server Error. Oddly enough no errors are being logged in the apache error logs.
I have also checked that mod_proxy and mod_proxy_http are enabled.
Any help is appreciated.

Related

Rewrite Rule returns 500 internal server error litespeed

how are you ? Today I'm with this problem that I cannot solve.
I created an instance to which I associated a docker container using cyberpanel, so far so good since if I enter the URL of the instance including the port I can use the app correctly. Now, I am trying to use the main domain of the instance as if it were the domain with the port and for this I used:
RewriteEngine On
RewriteRule ^(.*)$ http://localhost:9000/$1 [P,L]
When doing this my app is returning an error code 500.
Also, I tried to add in the OpenLiteSpeed panel (in the corresponding virtualhost) an "External App" that points to the url with the port.
I am using cloudflare also to reach the instances.
Some clue ? Thank you very much and have a good day / night
the htpp://127.0.0.1:8000 way only works for LiteSpeed Enterprise
for OpenLiteSpeed , you need to create the external app , and then use that name
RewriteRule ^(.*)$ http://StrapiBackend/$1 [P,L]

Rewrite Rules for apache (coming from IIS)

I thought I had this worked out... but I guess not. I am currently moving our server from IIS 7 to Apache (2.2.22 Ubuntu), I am able to get all my virtual hosts setup and running perfectly, but one site I am moving needs rewrite rules that I made in IIS, and I am unable to get working on Apache.
My rules are
RewriteEngine on
RewriteRule ^([^/]+)/?$ /index.php?LANG=$1 [L]
Nothing fancy, but I cannot get it to work, I get a service error if these rules are in the vhost conf file.
Anybody care to shed some (most lily obvious) light on an Apache new comer?
Cheers

htaccess issue with seo friendly urls - GoDaddy

OK, I'm looking to use mod rewrite to write seo friendly urls for my site. It works fine on my xampp local testing server. However, I'm having problems when trying to put it live, it doesn't seem to work at all.
Here's what I've written in my htaccess file:
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9]+)$ category.php?location=$1
So the idea is to change mysite.com/category.php?location=londonto mysite.com/category/london.
Initially I though it may be an issue with the ability to mod rewrite being switched on on GoDaddy's end, so I contacted GoDaddy to see if it that was the case and their response was that: "Mod_rewrite is an Apache Web server module installed on all of our Linux servers by default; it does not have to be installed or enabled. Our Linux hosting accounts support most mod_rewrite functions. Because enabling mod_rewrite is handled at a global level, you do not need to enable it in your httpd.conf file. You only need to add the desired code to the body of your .htaccess file."
And they bascially implied that the error is not with them and with my code. I'm not very experienced with mod rewrites and it seemed to work fine when I wrote it like this on other servers. Is there something special you have to write with godaddy? Am I missing something? Thanks!
Is that all in your htaccess file? What error do you get when visiting a desired URL, is it a 500 Internal Server error?
What I usualy add by default is an If-statement:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^category/([a-zA-Z0-9_-]+)$ category.php?location=$1 [L]
</IfModule>
By the way, note the _- at the end of the charset in the rule, for instance New York has a SEF version which is new-york, category/new-york would fail in your RewriteRule.

using proxy instead of redirection with htaccess rewriteRule

I'm developing a webapp and for the static files I'm simply using apache at localhost while the backend is on a couchdb instance running at localhost:5984.
The webapp interacts with files from the backend all the time. So what is happening when trying to test on apache all file requests to localhost:5984 are getting blocked due the cross-domain policy so the only way to get that working is starting the browser by setting flags to ignore that.
But again I get stuck when trying to test the app on mobile such ipad or iphone.
Currently I have this on my .htaccess file.
RewriteEngine on
# these are 302 http redirections instead of serving as a proxy
RewriteRule auth http://localhost:5984/auth [L]
RewriteRule db/([\s\S]+) http://localhost:5984/db/$1 [L]
RewriteRule send/([\s\S]+) http://localhost:5984/send/$1 [L]
# these are just redirections to static files and work great
RewriteRule ^([a-z/.]+) _attachments/$1 [L]
RewriteRule ^$ _attachments/ [L]
As you can see I have really no idea on how to deal with apache configuration unfortunately.
But what is happening right now is that for some of these rules apache is simply redirecting the page instead of provide it as a proxy server which causes the issue with cross-domain.
Also on the first auth rule I send POST and DELETE requests which as a redirection instead of proxy it won't pass the data being POSTed through.
So what I would like to achieve is to activate some kind of feature (if it exists) which will make apache simply render the page as it was on the localhost domain instead of redirect it. (I named this a a proxy, but perhaps that's not even the right term, sorry for any mistake committed with the nomenclatures).
Is is possible to achieve such action?
Thanks in advance
Have a look at these links / options:
[P] flag:
http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p
http://httpd.apache.org/docs/current/rewrite/proxy.html
mod_proxy (possibly -- but I think #1 should be enough if it's on the same server):
http://httpd.apache.org/docs/current/mod/mod_proxy.htm

How to configure apache (ubuntu) such that www.mysite.com will direct to www.mysite.com/drupal6/?

I am a newbie to ubuntu and apache. Can someone tell me how I could direct to
www.mysite.com/drupal6
when user address www.mysite.com?
Thanks a lot.
Cheers.
If you are running Apache and Ubuntu, there is actually a really easy way to force this redirect using a simple php script.
Create an index.php file in the root of your server and paste the following code into it
<?php header("location: drupal6/") ?>
This will cause the site to auto-redirect to the drupal6 folder whenever it is visited.
This should work. Create a file in the root folder of your server called .htaccess - the dot at the beginning is very important as this helps the server identify the file as a hidden / system config file.
Open the file and paste the following lines of code in :
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ www.mysite.com/drupal6/$1 [R,L]
This should force all traffic to the server to redirect to your custom folder.
A brief explanation of the .htaccess code
If you want rewrites to work, you have to enable the Rewrite Engine and tell the server to follow symlinks.
The second section establishes the rule - specifically applying it to all traffic on the standard web port of 80.
The final line tells the server to grab everything after the URL and append it to the new address (mysite.com/drupal6).
There's a lot more you can do with .htaccess files but you really need to Google for good examples to test out.
Look at Apache's mod_rewrite documentation. You will need a RewriteRule in your apache configuration at the minimum, you may also need RewriteCond's to define when the RewriteRule is used.
Your rewrite pattern will be rewriting the REQUEST_URI with something from: ^/$ to: /drupal6. The ^ and $ are essential to prevent Apache getting into an infinite loop while rewriting the base URI by only matching "/" and not "/anything-else".
I assume you're on a recent version of Ubuntu and Apache? If so, see the Apache 2.2 documentation on mod_rewrite.