Domain Name Forwarding With Masking Breaking Viewport - subdomain

So, I've discovered a rather interesting problem and was wondering if anyone else had come across it and maybe resolved it in some way.
I'm in the process of developing a responsive site. This site is hosted here. And the domain name iconclash.com is being forwarded with masking to the subdomain. Things were going well, however I noticed that on mobile devices my viewport meta tag wasn't working. After examining the page I noticed that this was being injected:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>ionclash.com</title>
</head>
<frameset rows="100%,*" border="0">
<frame src="http://nicholasarehart.com/designs/" frameborder="0" />
<frame frameborder="0" noresize />
</frameset>
This seems to be breaking the viewport tag. If you visit the subdomain directly, you'll see that the tag is working but if you visit the domain name that it being forwarded to it, it isn't. So, has anyone else ever seen this? Or resolved it? At the very least I think its something to be aware of.
Edit: seems someone else may have encountered this problem.

EDIT: I just recently switched away from using GoDaddy's subdomain forwarding w/masking to instead use Apache's mod_rewrite tool on my own server to setup subdomains. This is much better in my opinion because there is no use of frames, etc. that causes the problem with viewport.
NOTE: you need to add a wildcard subdomain to point to your server's ip before the below method will work.
My directory structure is as follows:
/srv/http/
---------subdomains/
-------------------www/
-------------------sub1/
-------------------sub2/
My main website's code is located in the www directory, so it fits into how the subdomains work but isn't really a subdomain perse, since it's the main site.
Below is what I have in my httpd.conf file. It is the only VirtualHost.
<VirtualHost *:80>
ServerAlias *.domain.com
#Rewrite Starts*
RewriteEngine on
#This will just force www.domain.com if
#only domain.com is given (to load our
#code in the www directory)
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.jmtk.co$1 [R=301,L]
#RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com
RewriteCond /srv/http/subdomains/%1 -d
RewriteRule ^(.*) /subdomains/%1/$1 [L]
</VirtualHost>
Here is just some configuration info from my server for reference:
[root#server ~]# apachectl -v
Server version: Apache/2.2.24 (Unix)
Server built: Mar 18 2013 13:57:39
[root#jmtksrv ~]# uname -a
Linux jmtksrv 3.8.11-1-ARCH #1 SMP PREEMPT Wed May 1 20:18:57 CEST 2013 x86_64 GNU/Linux
Hopefully this can be of use to you. It took me quite some time to finally get it just right after looking at several resources trying to explain creating subdomains with mod_rewrite.

Related

.htaccess file does not overwrite html and instead shows markup on page

I'm building a personal website, and I want my url links to look like domainname.com/example as opposed to domainname.com/example.html
I'm using fastcomet for my webhosting service. Under my public_html folder I have a .htaccess file. Here is the code for my .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
</IfModule>
My .htaccess file and all my html, css, js files are under home/username/public_html/ and I've removed the .html extensions from all my html files. After I applied these changes, I tried to get http://domainname.com/example and I saw the html markup as opposed to the rendered html such as:
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml">
<all my code .... />
</html>
Any suggestions on what I should do? I am placing the .htaccess file in the wrong directory? I also tried with and without the Ifmodule tags on the .htaccess file.
Thanks!
Yes, indeed, you should keep the file extension .html so you can have your files properly handled and your .htaccess to work as intended. It seems that in the meantime, you have actually posted the ticket to our Tech Support Team. Though there has been a slight misunderstanding regarding your request, a senior member of our team successfully excluded the processing of HTML and HTM files from the NginX service and they are now passed directly to Apache for your domain. As a result, all of your url links now look like domainname.com/example as opposed to domainname.com/example.html. Should you have any further requests, do not hesitate to contact us back!
I've removed the .html extensions from all my html files
This is why you see page code.
Rename the files back and use the following rewrite rule:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
</IfModule>
FastComet Team here! Part of our shared hosting environment is utilizing NginX as a reverse proxy to the Apache web service. This means that static content, such as HTML files, is processed directly by NginX and not by Apache. This is why any rules that you apply to the .htaccess file of your website are not making any actual changes. The requests to HTML files will be processed directly by NginX and they will not be passed to Apache so the .htaccess rules will be ignored.
There is an easy way of resolving that. We can exclude the processing of HTML and HTM files for your domain or even your entire hosting account. This way, those requests will be processed by the Apache web server, instead of NginX. In this case, the .htaccess rules that you apply will be taken into consideration by the system and they will work without any issues. To achieve that, simply submit a ticket to our Technical Support team and we would be happy to assist.

Whatever I do, .htaccess won't do the job

Working with .htacess file has always been a very frustrating experience for me. Someone please help.
This is what I want to achieve:
I am running Ubuntu 14.04.
Redirect my entire site (example.com) to a maintenance.html page.
Block everybody else except one IP, for example, I need to allow only 123.456.789.0
Here are my files:
Location of my index.html is /var/www/html
Location of my maintenance.html is /var/www/html
Location of my .htaccess file is /var/www/html
Contents of My .htaccess file:
#Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
#301 Redirect Old File
Redirect 301 /index.html /maintenance.html
#Block users by IP
order allow,deny
deny from all
allow from 123.456.789.0
Please help me understand:
Is the location of each of the above files right? In what cases, the
page ends up in 500 internal server error?
What changes should I make in
/etc/apache2/apache.conf
/etc/apache2/sites-enabled/000-default.conf OR
/etc/apache2/sites-available/000-default.conf
Is is necessary to run a2enmod rewrite?
Should I add <IfModule mod_rewrite.c> and </IfModule> as header and footer in any of the above config files?
Sorry for too many questions, but I really want know it all this time.
Thanks in advance.
Is the location of each of the above files right? In what cases, the
page ends up in 500 internal server error?
A "500 Internal Server Error" message means there's an error and you're expected to check the server logs for the exact details. Apache will not display the error message to be seen by everyone.
What changes should I make
It depends on what the problem is. If the problem is "500 Internal Server Error" that means that we still don't know what the problem is.
Is is necessary to run a2enmod rewrite?
That command enables mod_rewrite. You need to enable it if it isn't enabled. You don't need to enable it if it's already enabled.
It's worth noting that this command is not part of official Apache distribution. Some Linux distros (namely Debian and derivatives) change third-party packages to match their configuration preferences, as in this case.
Should I add <IfModule mod_rewrite.c> and </IfModule> as header
and footer in any of the above config files?
As documentation explains, this block can be used to ignore directives when a given module is not installed. This can be useful for configuration templates to be distributed and optional features. In your case, it'll silently ignore your code if mod_rewrite is not available—you don't want that.
Last but not least:
order allow,deny
deny from all
allow from 123.456.789.0
... belongs to the old (and really hard to understand) Apache/2.2 syntax. If you are using Apache/2.4* you may want to try Require.
(*) Some distros hate bundling recent software but 2.4 has been around for several years
Thanks to #OlafDietsche and #ÁlvaroGonzález for this quick help. I am keeping their suggestions here so somebody like me will find it useful.
The problem is with my goals, not with the syntax. With their comments and answers, I came to know that my 2 goals were mutually contradicting ones.
I configured .htaccess to do both page-redirection and IP block. But if I am blocking (almost) everybody from accessing the site, page redirection makes no sense.
The required configuration in .htaccess is:
#Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
#301 Redirect Old File
Redirect 301 /index.html /maintenance.html

Wordpress JsonAPI - /wp-json/ was not found on this server

I am using the following plugin Json Rest API.
To test the plugin the documentation states that I should just use:
$ curl -i http://testpress-maxximus.rhcloud.com/wp-json/
HTTP/1.1 404 Not Found
Date: Sat, 24 May 2014 07:01:21 GMT
Server: Apache/2.2.15 (Red Hat)
Content-Length: 303
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /wp-json/ was not found on this server.</p>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at testpress-maxximus.rhcloud.com Port 8
0</address>
</body></html>
As you can see nothing is found by the URL. Any recommendations if there is a problem with the API or wordpress?
I appreciate your reply
The current version of REST api for sites with pretty permalinks not enabled, the url
yoursite.com/?rest_route=/
will work .
The WordPress JSON API depends on pretty permalinks, make sure you have them enabled for the site.
In my case, I got this error after installing/configuring apache2 on my local linux machine. I finally found the error to be cause by the rewrite module not being enabled which I fixed using,
sudo a2enmod rewrite
as well as ensuring that my apache2.conf file (located in the folder /etc/apache2) has its<Directory> directive 'AllowOverride' set to all rather than none, from
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
to
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
then I restarted apache2 service and the problem was resolved.
I have faced this issue several times . The solution is this :
Login into your Wordpress site: example.com/wp-admin
Then click on settings
Then click on permalinks
Then set permalinks to "post-name"
Save Changes
Sometimes the solution is crazy and easy! Go to the permalink settings by moving to Admin -> Settings -> Permalinks...then just hit Save Changes without doing anything else! This refreshes the memory of WordPress.
Why is that? For a situation I had before, I had changed the main website URL so I had to refresh the permalinks as well.
I had this same issue and wanted to post my solution in case anyone else comes across this answer and the other answers don't solve the issue, as this happened with me.
In my case I didn't have a .htaccess file with Wordpress' default mod_rewrite rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This solved the issue for me. Per the documentation:
WordPress uses this file to manipulate how Apache serves files from
its root directory, and subdirectories thereof. Most notably, WP
modifies this file to be able to handle pretty permalinks.
I was running WP on a local dev environment in a subdomain of localhost (eg mysite.localhost:8888)
The solution for me was to update the virtual host config in httpd-vhosts.conf to set directory options, similarly to Aurovrata's answer:
<VirtualHost *:8888>
ServerName mysite.localhost
DocumentRoot "/Users/myusername/mysite"
<Directory /Users/myusername/mysite>
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
Faced a similar issue, turns out that Apache's mod_rewrite module wasn't enabled. Worked fine after enabling it.
For me, this issue was due to the WP site being developed at the root of a staging URL (ie example.com) but when put live it was installed in a sub-directory (ie example.org/wp)
Before I could make the suggestion from this comment work I had to chmod 664 .htaccess to make it writable by Wordpress. I then resaved the Permalinks as suggested and Wordpress updated the RewriteBase in .htaccess to /wp
If you have correctly installed the plugin, be sure to flush the rewrite rules.
This can be accomplished with the wp-cli: http://wp-cli.org/commands/rewrite/flush/

Server side changes in Angular html5 mode

I was wondering if any one can tell me what are the server side changes which needs to be done when you change your mode in to html5 in Angular js. because When I did tried to change the it to html 5 mode I was unable to go in to my inner html pages. in Angular API it says that suers need to do a server side changes as well.
what are the server side changes
do we need to do any other changes as well ?
You should distinguish two type of calls:
HTML calls from the browser. These should be all remapped to serve your index or whatever.
JSON API requests. These should pass through to your app server.
How to distinguish between these two types of calls, and how to remap the former, depends strongly on your setup.
If you are using nginx, for instance, a combination of checking $http_accept to be application/json (see http://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Requests and http://wiki.nginx.org/HttpCoreModule#.24http_HEADER) and rewrite (http://wiki.nginx.org/HttpRewriteModule#rewrite) you can achieve what you want.
You need to setup your server to rewrite everything to index.html per: https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode ...
<VirtualHost *:80>
ServerName my-app
DocumentRoot /path/to/app
<Directory /path/to/app>
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
My app has params passed to a controller (via ui-router) so before html5mode I would goto
www.blah.com/angapp/#/myUIrouterController?param_x=1&param_y=2
Guessing browsers know that /#/ folder path part should serve index.html.
Now that # would be gone with html5mode, the server by default doesn't know to serve the index.html for that folder since the url will just be:
www.blah.com/angapp/myUIrouterController?param_x=1&param_y=2
myUIRouterController isn't a real file so the server would just serve a 404, Hence why I think the rewrites are needed so it knows to send everything to index.html (so above in combo with the <base> tag should work... note: requireBase is optional but heard it helps older browsers like IE9 maybe).

Default 403 page not showing up

I recently set up a few new folders in my server, but I wanted to turn them and all their subfolders forbidden. So, using .htaccess, I simply used deny from all. The issue here is that it's redirecting me to my host's 404 page (which has a lot of advertisements, join us, it looks like their front page), instead of the regular 403 page.
This seems like a very trivial question, but I couldn't find the answer anywhere. How do I get everything in that folder to use the classic 403 page, being this:
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<h1>Forbidden</h1>
<p>You don't have permission to access /example/example2/exampleC/
on this server.</p>
</head>
</html>
Which changes depending on which folder I just entered. If In /example/ I have /example1/, /example2/ and /example3/, how do I make it so that if I enter /example1/, I get a 403 page that says I don't have access to /example/example1/?
This may seem a bit overly (needlessly) complicated.
let's debug step by step
for debugging please follow these steps
Rename in your DocumentRoot .htaccess to .htaccess_safe
Create a folder in DocumentRoot "test"
Insert in that folder a .htaccess with following content
RewriteEngine On
RewriteRule ^(.*)$ http://google.de [L,R=301]
Open in your Browser http://example.com/test/ [you should redirect to google]
If this works ... read more under step 5.
If not ... put this .htaccess in the DocumentRoot Folder and open in your Browser http://example.com/test/ if this doesn't run too, stop debugging. If it works, your Server isn't able to exec .htaccess in subfolders (check for that the rights of the .htaccess file on your server group, user and chmod .....
(5) Rename your .htaccess_safe back to .htaccess and change line 12 RewriteRule ^$ http://www.avatarchan.net/site/ [R=301,L] to #RewriteRule ^$ http://www.avatarchan.net/site/ [R=301,L] and try again