On local development with Wordpress on iOS, resources fail to load - ios

Have been developing a Wordpress theme using MAMP (localhost:81), and I am now testing some responsive parts on iOS (using my IP (192.168.1.15:81).
Some images are hard-coded (i.e. not changeable from the admin), using the following code:
<img src="<?php echo get_template_directory_uri(); ?>/images/brand-id.svg" onerror="this.src=<?php echo get_template_directory_uri(); ?>/images/brand-id.png" alt="Brand Name" />
It displays correctly both on localhost and IP, from desktop, but using the IP on iOS (8.1), it cannot find the resource, because it loads it in this form:
http://localhost:81/alexe.ro/wp/wp-content/themes/brand/images/brand-id.svg
I am using the Relative URL Wordpress plugin, but that seems to only work for loading the css/js/fonts.
Other details: the dynamic images (the ones uploaded from the cms) load perfectly.
How can I get the 'hard-coded' resources to switch between localhost and the IP, if necessary?
Thank you in advance.

The problem isn't related to IOS, it will fail to read the correct path from any machine in the LAN, apart from your dev one.
One of the solution is:
To make WP to always run under http://IP:port rather than http://localhost:port
In your case, it looks like your WP is in a sub directory /wp, then login to admin panel, and go and update as below:
Settings > General > WordPress Address >> http://192.168.1.15:81
Settings > General > Site Address >> http://192.168.1.15:81/wp
It's also recommended to set the dev machine with a static/preserved IP address on the router, so it will always receive the same one.
I also like the solution posted by #asherstoppard Well, you can play around and find which fits you the best.
One more tip: Backup your database first, in case anything bad happened.

Try adding the following to your wp-config.php file.
define('WP_HOME','192.168.1.15:81');
define('WP_SITEURL','192.168.1.15:81');
Your site_url() will be set to localhost:81 and as such will be attempting to access localhost on your device through get_template_directory_uri().

Related

Is it possible to share my localhost with someone on a different network?

I am working with a designer and I'd like them to have access to the interactions I've implemented on the site we're working on. However this time, I have 2 issues. My localhost is configured to a subdomain:
http://store.teststore:3000/ and we're on different networks. Is there anyway to work around this?
ngrok should work for you. Download and install it following these instructions here: https://ngrok.com/download. Documentation on how it is used can be found here https://ngrok.com/docs. Once installed running the below command should work for you (depending on the hosting environment):
ngrok http -host-header=rewrite store.teststore:3000
You will need to give the URL generated by ngrok and displayed in the cmd prompt to the designer.
Update: Handling absolute redirects
Based on your comment it sounds like, after login, your site does an absolute redirect (the full URL is specified). If it is possible I would change your code to do a relative redirect where the domain is omitted. You could also make your root domain configurable in the absolute redirect and configure it to be the ngrok domain provided for now. Lastly, you could attempt to configure your DNS with a CNAME record following ngroks Tunnels to custom domains documentation. This last option, however, requires a paid for ngrok subscription.
Install ngrok if you haven't yet and CD into your project directory and invoke ngrok. Note Your application must be running locally on the same port number ngrok will be running.

Accessing decommissioned website in Umbraco

I have a website that we used to access via Umbraco. It was decommissioned on 11/22 to a new site with same name. There is some content we need to retrieve. I was thinking maybe we could access it via IP but that doesn't work. Anyone know how to accomplish this so we can log on to the old site via umbraco without interfering with the new site.
If you log into the server and find the site in IIS, you could set up new bindings on that site, so it responds to decommissioned.mysite.com. Then add a host file entry to your local machine, so decommissioned.mysite.com sends you to your decommissioned site.
When your computer performs a DNS lookup, the host file is the first place it will look. This means you can use the host file to bypass the DNS settings configured for the public. It comes in handy when you have a dev version of a site that isn't ready for the world, yet. On windows you can find the host file at C:\Windows\System32\Drivers\etc\hosts. You will probably need to run your text editor as an administrator to edit the file. This is what host file entries look like:
123.123.123.123 mydomain.com www.mydomain.com
321.321.321.321 www.myotherdomain.com blog.myotherdomain.com

Make local development work with Facebook/Google APIs

I'm working on implementing omniauth into a Rails project. My problem is that the authentication providers - Twitter, Google, Facebook etc all require me to create an application with a url that limits authentication requests from anywhere other than the url. I need to be able to to test locally but also run code in production, but Facebook for example doesn't allow 2 domains and doesn't allow localhost anyhow.
So what are my options?
At work, we have multiple applications setup for the different environments. On local, add an entry in /etc/hosts (assuming you are on linux) eg: 127.0.0.1 mydomain.local.
On the facebook app setup for the local environment, add this as the url. Most things, except where facebook needs to scrape your site (Like buttons) work.
Here's a blog post with my solution: http://make.bettermistak.es/2012/05/03/how-to-create-a-local-sandbox-facebook-app/
Here's the relevant bit: "Facebook verifies that all requests for your app are coming from the right domain–they don’t allow requests from localhost or 127.0.0.1–and this info can be updated in your apps settings under Hosting URL. Add “local.herokuapp.com” to your Hosting URLs and save this setting. Then edit your /etc/hosts file so that local content is under the domain local.herokuapp.com. This file is hidden, so from the command line enter sudo vi /etc/hosts. (Substitute your favorite editor for vi.) We need to use sudo, because this file is locked. Add the line “127.0.0.1 local.herokuapp.com” below “127.0.0.1 localhost” and save and quit your text editor."
As far as I know, you must sing up two apps for you app.(one for remote side, one for local side)
Fortunately, there is a way to reduce the complication(Assuming you are working on linux):
You can configure you .bash_profile (local machine and remote machine separately):
export YOURAPP_APP_ID="XXXXX"
export YOURAPP_APP_SECRET="XXXXX"
And use ENV['YOURAPP_APP_ID'] and ENV['YOURAPP_APP_SECRET'] in your code.
For example, you can code like this in rails:
config.omniauth :facebook, ENV['YOURAPP_APP_ID'], ENV['YOURAPP_APP_SECRET']
By this way, you can use the same code in both local and remote side. It will be much easier for maintaining.
If you are using Heroku to host your application, you can refer to this page to config the environment variables.
I have created two apps on Facebook one of which i run in sandbox mode for development purposes. Would that be an option for you?

Chrome browser doesn't like *.loc domain without http://?

For web development on localhost I'm using domains with .loc extension at the end of a domain name.
For example: if I work on a site roses.com, the local development domain would be roses.loc
(defined in hosts file and IIS as a host-header in binding)
My preferred browser (the main browser I use for development is Chrome) but unfortunately
it does not recognize a domain name with .loc extension as http://rose.loc - it throws me onto a google search page each time I would type in rose.loc (without http://) in the beginning..
Have you experienced this in a similar way ? Is there some solution to that ?
Because during intensive development testing with clearing browser cache and restarting the browser for various reasons, it's getting pretty annoying to be thrown at a google search page instead of the development page where I expect to notice some changes, each time I forget to type in http:// before the url (and Chrome is the one who hides it by default, anyway..)
Google Chrome is pretty "smart" with this. It uses a list of known-good TLDs and assumes everything else is just a search term that happens to end in a dot followed with some characters.
99% of the time that's perfectly fine. It's "only" us developers and a few people with strange network setups that have to suffer for the good of the majority ;-)
You can try using .local as your TLD, as that's a defined domain for referencing local domain names (at least it's used in some mDNS systems).
The issue has been entered as #30636 in the Chromium bug tracker. One workaround that often (but not always) seems to work is to append / to your hostname. So try roses.loc/.
I've created a search engine with a keyword of 'l' (my local TLD is .l). The URL for the search engine is http://%s.l. Then, I simply type "l mysite" in the address bar and it takes me to mysite.l.
Here is a workaround I came up with for this bug: http://code.google.com/p/chromium/issues/detail?id=30636#c38
I have Chromium installed on Linux Mint, and have a few localhost websites here. (I use Firefox for all of my work, so I have just discovered something here with Chromium.) My local sites are called morse and a.z. I had to enter http://morse/ and a.z/ respectively to get these sites to load the first time. They produced quick links on the new tab's otherwise blank page.
After closing Chromium, I reopened it and I could enter just morse/ and a.z to visit these sites. Since I've never seriously used this browser, I have not tailored any settings in it. (I did not use the quick link icons, but instead typed in the address bar.)
My findings confirm the localhost example.TLD/ entry does work when entered for the first time.
About Chromium: I am using Version 106.0.5249.119 (Official Build) for Linux Mint (64-bit).

Can I edit an iPad's host file?

I doubt this is possible without extensive jail-breaking, but is it at all possible to edit the iPad's (or any iOS device's) hosts file?
The previous answer is correct, but if the effect you are looking for is to redirect HTTP traffic for a domain to another IP there is a way.
Since it technically is not answering your question, I have asked and answered the question here:
How can I redirect HTTP requests made from an iPad?
No, you can't change iPad's host file(without jailbreak), but can workaround.
Here is my scenario:
Mac OS X, with IP 192.168.2.1, running a web app
iPad, the device you would like to test the web app
Charles (for Mac), enables HTTP proxy for your iPad
I am going to test the web app running in my Mac via iPad, but I can't access directly to it.
The solution works for me:
Firstly, make sure that your server and iPad are in the same local network.
Then, set up Charles proxy, in the menu "Proxy > Proxy Settings...", fill in Port(mostly 8888) and toggle Enable transparent HTTP proxying.
Setup proxy setting in iPad.
Now you can visit your web app in iPad.
Of course you can use other proxy tools like Squid or Varnish in Linux, or fiddler in Wondows.
No. Apps can only modify files within the documents directory, within their own sandbox. This is for security, and ease of installing/uninstalling. So you could only do this on a jailbroken device.
The easiest way to do this is to run an iPad simulator using XCode and then add an entry in the hosts file (/etc/hosts) on the host system to point to your test site.
I needed the same functionality, and doing jailbreak is no-no. One solution is to host yourself DNS server (MaraDNS), go to your wifi settings in ipad/phone, and add your custom DNS server there.
The whole process took me only 10 minutes, and it works!
1) Download MaraDNS
2) Run mkSecretTxt.exe as administrator
3) Modify mararc file, mine is:
ipv4_bind_addresses = "put your public IP Here"
timestamp_type = 2
random_seed_file = "secret.txt"
csv2 = {}
csv2["Simple.Example.com."] = "example.configuration"
Add file called "example.configuration" into the same folder where run_maradns.bat is.
4) Edit your example.configuration file:
Simple.Example.com. 10.10.13.13 ~
5) Disable all Firewalls (convenience)
6) Run file "run_maradns.bat"
7) There should be no errors.
8) Add your DNS server to list, as shown here: http://www.iphonehacks.com/2014/08/change-dns-iphone-ipad.html
9) Works!
Yes, you can edit the iPad hosts file, but you need to be jailbroken. Once you've done that, download Cydia (app market), and get iFile. The hosts file is located within "/etc/hosts".
I would imagine you could do it by setting up a transparent proxy, using something like charles and re-direct traffic that way
Workarond I use for development purposes:
Create your own proxy server (One option would be: Squid on Linux).
Set your hosts file with your domains.
Set the proxy server on the IPAD/IPHONE and you can use with your hosts.
I know it's been a while this has been posted, but with iOS 7.1, a few things have changed.
So far, if you are developing an App, you MUST have a valid SSL certificate recognized by Apple, otherwise you will get an error message on you iDevice. No more self-signed certificates. See here a list:
http://support.apple.com/kb/ht5012
Additionally, if you are here, it means that you are trying to make you iDevice resolve a name (to your https server), on a test or development environment.
Instead of using squid, which is a great application, you could simply run a very basic DNS server like dnsmasq. It will use your hosts file as a first line of name resolution, so, you can basically fool your iDevice there, saying that www.blah.com is 192.168.10.10.
The configuration file is as simple as 3 to 4 lines, and you can even configure its internal DHCP server if you want.
Here is mine:
listen-address=192.168.10.35
domain-needed
bogus-priv
no-dhcp-interface=eth0
local=/localnet/
Of course you have to configure networking on your iDevice to use that DNS (192.168.10.35 in my case), or just start using DHCP from that server anyway, after properly configured.
Additionally, if dnsmasq cannot resolve the name internally, it uses your regular DNS server (like 8.8.8.8) to resolve it for you. VERY simple, elegant, and solved my problems with iDevice App installation in-house.
By the way, solves many name resolution problems with regular macs (OS X) as well.
Now, my rant: bloody Apple. Making a device safe should not include castrating the operating system or the developers.
If you have the freedom to choose the hostname, then you can just add your host to a dynanmic DNS service, like dyndns.org. Then you can rely on the iPad's normal resolution mechanisms to resolve the address.
You can also make use of a proxy server on your iPhone or iPade via mobile internet (3G) by using a iPhone Mobile proxy generator:
http://iphonesettings.net/mobileproxygenerator.php
Just enter the apn of your carrier (with apn username/password if needed) and the proxy server you want to go through and tap Generate
Problem Restated: Bypassing DNS Resolution
The problem the OP is trying to solve is NOT hacking hosts files on iPads per se, but rather bypassing DNS Resolution of a specific published DNS record by creating a static, local IP:name mapping on their device.
Solution:
A better- and more scalable- way is to create the static IP:Name mapping that you'd create in the hosts file on the device and instead create it on the router and then point your DHCP addressed clients to that router as the primary source of DNS resolution as I document (with annotated screen shots) HERE.
Conclusion:
When testing a new site you need to check the display of it on multiple devices to ensure there's no funky display or usability issues. Bypassing DNS checking using static local IP:Name mappings would require each developer to hack the hosts files for each of their devices and then remember to unwind the changes in all their devices after testing.
And were it even possible to hack an iPad's hosts file as the OP enquired about, in many organizations the Developers IT assets will be locked-down and they won't they have administrative permissions to do such tinkering.
Better to make the static mapping to bypass the published DNS record in the router and then you can delete it in one place after testing is completed.
You need access to /private/etc/ so, no. you cant.
Best Answer: Simply add http or https in your browser, the IP address, colon and port number. Example: https://123.23.145.67:80

Resources