My site uses nginx. I use apache only for large file uploading to the server. I have a script upload.php which I POST the files to via a flash uploader script.
Apache runs on a subdomain, so I post files to upload.domain.com/upload.php
Is there any way to prevent apache from serving the actual site on that subdomain? ideally I want to post files to upload.subdomain.com and have it be directed to upload.php on that subdomain
I mean I could setup a different document root for apache and thats it, but are there any other ways?
If I understand correctly you want all requests to upload.domain.com to be directed to upload.php? A RewriteRule inside the VirtualHost that catches all requests should work:
RewriteEngine On
RewriteRule . /full/path/to/upload.php
Related
I have a basic project running on IIS 8.5
sites
-> test.domain.com
--->virtualPath
----->index.html
On the browser when enter https://test.domain.com/virtualpath, it is return 301 (redirect) to test.domain.com/virtualpath/
I don't have any URL Rewrites in IIS configuration. Just trying to figure out why it is redirecting to test.domain.com/virtualpath/
How can avoid this 301 redirect?
The short answer is that IIS doesn't handle extensionless URLs very well. URLs are processed based on the file extension, otherwise it's presumed to be a directory you're looking to get served. The normal convention however is to omit the index.html file.
But most services like IIS take that for granted, and if nothing is specified, it will lookup if there's a /index.html.
Lets take a simple example:
google.com
In reality what's being served to you is:
google.com/index.html
Lets take your request as an example https://test.domain.com/virtualpath
test.domain.com
- virtualPath/
- index.html
As you can see, you're essentially trying to get a directory rather than a specific file. It's up to IIS to try to find and understand that you want a file instead of a directory now. That's why you're getting a 301. It's redirecting you to the /index.html file.
I've read plenty of Stackoverflows but I seem to be missing something.
I have a PHP application running on https://subdomain.example.com/page/x but for SEO reasons I want people/bots to see https://example.com/subdomain/page/x.
I can rewrite the URL by using:
RewriteEngine on
RewriteCond %{HTTP_HOST} subdomain.example.com
RewriteRule ^(.*)$ https://example.com/subdomain/$1 [L,NC,QSA]
This rewrite results in: https://example.com/subdomain/page/x, but I keep recieving a 404 error since the "main" domain doesn't know the path /subdomain/page/x of course.
What I want is to have the URL https://example.com/subdomain/page/x but run it on https://subdomain.example.com/ in the background since this is the place where the PHP application is running.
Is this possible? How should I do this?
There is no strong SEO reason not to use subdomains. See Do subdomains help/hurt SEO? I recommend using subdirectories most of the time but subdomains when they are warranted.
One place where subdomains are warranted is when your content is hosted on a separate server in a separate hosting location. While it is technically possible to serve the content from a subdirectory from the separate server, that comes with its own set of SEO problems:
It will be slow.
It will introduce duplicate content.
From a technical standpoint, you would need to use a reverse proxy to on your example.com webserver to fetch content for the /subdomain/ subdirectory from subdomain.example.com. The code for doing so in the .htaccess file of example.com would be something like:
RewriteEngine on
RewriteRule ^subdomain/(.*)$ https://subdomain.example.com/$1 [P]
The [P] flag means "reverse proxy" which will cause the server to fetch the content from the remote subdomain. This will necessarily make it slower for users. So much so that it would be better for SEO to use a subdomain.
For this to work you would also need to leave the subdomain up and running and serving content for the main server to fetch. This causes duplicate content. You could solve this issue by implementing canonical tags pointing to the subdirectory.
This requires several Apache modules to be available. On my Debian based system I needed to run sudo a2enmod ssl proxy rewrite proxy_connect proxy_http and sudo service apache2 reload. I also had to add SSLProxyEngine on in my <VirtualHost> directive for the site I wanted to use this on.
I have a React application hosted on my server and I need to always load index.html file for every request users make.
Let's say that I have a website that has the address xyz.com, and the root directory contains the React build files, including this index.html file. There are many routes that users can specify to access to certain parts of the website, for example to register on the website they can access xyz.com/register. So, what I want to accomplish is instruct server to always serve this index.html every time users access my site, even though they are visiting different routes of the website.
So I'm assuming that this is something that I can set up in the .conf file for the website, and if it is, can you please let me know how I can achieve it?
You can use the below rewrite rule.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteRule .* /index.html [L,R=302]
I am not sure whether this is possible. I need to upload 1 file to web server. Then download this file as multiple parts/chunks with fixed size. In other words, after request for download of http://my.domain/dir/file123.bin, the web server has to run some script and give it the URL or only 123 as parameter. The same is possible with: http://my.domain/dir/?chunk=123 - then index.php or index.aspx will return chunk #123. Can the same be done with dir/file123.bin syntax?
On apache simply use mod_rewrite:
RewriteRule ^/dir/file([\d]*).bin$ /dir/?chunk=$1 [L,PT]
On IIS there is a URL Rewrite extension that seems to do almost the same thing.
I just started using mod_rewrite for a web project, and I had finally got it to redirect the way I wanted but I have ran into a big problem. If I redirect the request /trades/id to trades.php?id=id, the browser looks for all of the assets of trades.php inside of the non-existent trades/ directory instead.
Here is my .htaccess
# Enable Rewriting
RewriteEngine on
# Rewrite user URLs
# Input: trades/ID/
# Output: trades.php?id=ID
RewriteRule ^trades/(\w+)/?$ index.php?req=trades&id=$1
The problem that arises is that when I load the page localhost/trades/ID, The browser is attempting to load assets like so,
http://localhost/trades/js/cardy.js
which ofcourse does not exist on the server. I'm still really new to mod_rewrite, so I'm not sure how to fix this problem.