I have a url
api/something/json?callback=abc and I want to redirect it to
dothis.php?strEndPoint=something&callback=abc&format=json
The base htaccess I tried was:
RewriteRule ^api/(.)/(json)?callback=(.) client.php?strEndPoint=$1&callback=$3&format=($2)
Doesn't appear to work : p
tested
using .*
RewriteEngine On
RewriteCond %{QUERY_STRING} callback\=(.*)
RewriteRule /api/(.*)/(json) /client.php?strEndPoint=$1&callback=%1&format=$2 [R=301]
you can remove r=301 just for test
$ curl localhost/api/1111/json?callback=2222 -I
HTTP/1.1 301 Moved Permanently
Date: Fri, 01 Nov 2013 03:16:25 GMT
Server: Apache/2.2.24 (Unix) DAV/2 mod_ssl/2.2.24 OpenSSL/0.9.8y
Location: http://localhost/client.php?strEndPoint=1111&callback=2222&format=json
Related
I am trying to use htaccess to redirect a site to another site (hosted on the same Virtualmin server)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1.com$
RewriteRule (.*)$ https://sub.domain2.co.uk$1 [P]
</IfModule>
This code is just giving a 500 Internal Server Error.
In the error logs, I can see:
[Tue Jul 09 18:00:29.276394 2019] [ssl:error] [pid 17001] [remote 104.26.6.131:443] AH01961: SSL Proxy requested for sub.domain2.co.uk:80 but not enabled [Hint: SSLProxyEngine]
[Tue Jul 09 18:00:29.276436 2019] [proxy:error] [pid 17001] AH00961: HTTPS: failed to enable ssl support for 104.26.6.131:443 (sub.domain2.co.uk)
(I've changed the domains above to generic for privacy, but they match the two in my htaccess example)
I've also checked the apache config, and ssl engine is ON
Hard to say what is wrong, but here is a slightly modified version of your attempt that prevents some issues:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain1\.com$
RewriteRule ^/?(.*)$ https://sub.domain2.co.uk/$1 [P]
An alternative would be to use the proxy module directly, without the rewriting module:
ProxyPass / https://sub.domain2.co.uk/
ProxyPassReverse / https://sub.domain2.co.uk/
The entry in the error log file indicates that you have an issue with the ssl certificate on that proxied page... Could it be that the certificate does not match the host name you use in the target of your proxy rule?
On the localhost it is running. But when I upload it, its throwing an 500 error.
I checked:
mod_rewrite (loaded - phpinfo(8))
extension intl (enabled)
I tried:
Deleting all the cache files
Thats my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Errorlog of PHP:
[Sun Jan 17 11:04:02 2016] [warn] RSA server certificate wildcard CommonName (CN) `*.webpack.hosteurope.de' does NOT match server name!?
Any ideas?
So at the end it was pretty simple and stupid, but maybe it will help someone.
My Webhosting was using PHP 5.3 - Update to 5.6 and e´voila!
I have a favicon.ico linked to my site.
<link rel="shortcut icon" href="http://nameofsite.com/favicon.ico" type="image/x-icon" />
However, you'll notice that when you visit, you get the error message:
The image "link-to-image" cannot be displayed because it contains errors.
I tried uploading the favicon.ico file to another server, and it loaded without any problems.
Which leads me to believe perhaps my htaccess file is affecting it?
In my htaccess file, I make sure to add rules that exclude anything dealing with the 'ico' extension, so that the ico file can be viewed.
Some rules include:
# SITE NAVIGATION
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(css|gif|jpg|jpeg|png|ico|txt|xml|js|pdf|html)$ /root/to/public_html/nameofsite.com/index.php [NC,L]
# ANTI-HOTLINKING
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?nameofsite.com(/)?.*$ [NC]
RewriteRule .*\.(gif|jpg|jpeg|bmp|png|ico|css|js|pdf)$ http://nameofsite.com [R,NC]
However, I cannot find any errors with these rules.
Any suggestions are welcome, I'm kind of at a loss.
Try reuploading your favicon.ico file, it is empty:
$ curl -i http://thejadednetwork.com/favicon.ico
HTTP/1.1 200 OK
Date: Thu, 19 Dec 2013 10:15:00 GMT
Server: Apache
Last-Modified: Mon, 24 Sep 2012 01:13:21 GMT
Accept-Ranges: bytes
Content-Length: 0
Content-Type: image/x-icon
Another suggestion, this rule:
RewriteCond %{HTTP_REFERER} !^http://(www\.)?nameofsite.com(/)?.*$ [NC]
would also match http://nameofsite-com.example.com/. You probably meant:
RewriteCond %{HTTP_REFERER} !^http://(www\.)?nameofsite\.com(/|$) [NC]
Hey guys I got a tricky one here, but I believe it will allow me to bypass the need for a PHP controller file for forwarding. I have a url that I hit example.com/ if it has no following sequence, it will route like this
#example.com
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^$ http://www\.example2\.com/?CampID=dm/DMdefault [R=301,L]
The question is the second redirect. If I want to slice the first two (alphanum) as one part of the forwarding url, and the next five as the second part, would this work?
RewriteMap lc int:tolower
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^(\w{2})(\w{5})$ http://www\.example2\.com/landing/external-marketing/direct-mail/${lc:$1}?CampId=${lc:$1$2} [R=301,L]
This *should normalize case, and forward http://example.com/BA025JD to
http://www.example2.com/landing/external-marketing/direct-mail/ba?CampId=ba025jd correct?
You can't use the RewriteMap directive inside an htaccess file, you need to define maps in server or vhost config. Unfortunately, apache chooses not to bring that to your attention. If you use a map that hasn't been defined, it just silently does nothing.
However, once that map has been defined, your rules work for me:
my request
GET /A1b2C3d HTTP/1.1
Host: example.com
apache's response, with the lc map defined
HTTP/1.1 301 Moved Permanently
Date: Mon, 15 Oct 2012 18:44:37 GMT
Server: Apache
Location: http://www.example2.com/landing/external-marketing/direct-mail/a1?CampId=a1b2c3d
Content-Length: 349
Content-Type: text/html; charset=iso-8859-1
A request to http://localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites
gets redirected as follows:
> Request URL:http://localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites
> Request Method:GET
> Status Code:301 Moved Permanently
Response headers:
> HTTP/1.1 301 Moved Permanently Date: Thu, 06 Sep 2012 14:32:41 GMT
> Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4
> mod_perl/2.0.4 Perl/v5.10.1 Location:
> http://localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites/
> Content-Length: 417 Keep-Alive: timeout=5, max=100 Connection:
> Keep-Alive Content-Type: text/html; charset=iso-8859-1
I am not sure what causes this redirect.
I have the following .htaccess in folder c:\xampp\htdocs\SAMPLE-CODES\backbone-mysql-reading-json\:
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
This is probably because of the mod_dir and the DirectorySlash directive that's doing the redirect. With it on, when apache looks at a URI and thinks it's accessing a directory, and is missing the trailing slash, it 301 redirects to the URI with the trailing slash. It's always turned on by default because there's an information disclosure security issue if you have it turned off. But if you are routing everything through an index.php script, it may not even matter and you can turn it off by simply adding DirectorySlash Off in your htaccess file (and turn it on for directories that you can access directory, like css or js or images, etc.