• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

url

Metadata URL

January 15, 2022

Here’s the metadata URLs for both AWS and GCP.

curl http://169.254.169.254/computeMetadata/v1/ -H "Metadata-Flavor: Google"
curl http://169.254.169.254/latest/meta-data/

curl http://169.254.169.254/computeMetadata/v1/ -H "Metadata-Flavor: Google" curl http://169.254.169.254/latest/meta-data/

Filed Under: Cloud Tagged With: aws, gcp, metadata, url

Change WordPress URL

June 6, 2021

There are multiple ways to change URL in WordPress.

Here’s one via wp-config.php.

define( 'WP_HOME', 'http://example.com' );
define( 'WP_SITEURL', 'http://example.com' );

define( 'WP_HOME', 'http://example.com' ); define( 'WP_SITEURL', 'http://example.com' );

If you have a redirect in Apache, comment it out.

#Redirect permanent / https://yourdomain.com/

#Redirect permanent / https://yourdomain.com/

This is by far the easiest way to change URL in WordPress.

Filed Under: Linux, WP Tagged With: change, config, url, wordpress, wp-config.php

GCP SDK Auth Login

December 24, 2019

Here’s how to login to GCP from Google SDK.

gcloud auth login

gcloud auth login

  • Click on the URL to authenticate on your browser.
  • Login with your Google Account. Use MFA if prompted.
  • Click Allow when prompted.

You will then be taken to a page that you have successfully logged in.

Filed Under: Cloud Tagged With: account, auth, gcp, login, mfa, sdk, url

URL Encode

August 2, 2018

If you need to special characters encoded in a URL, these sites really come handy. Why is there a need to encode? URLs accepts only alphanumeric characters and a limited number of special characters. For example, : and / are common characters you’ll find in URLs. Meanwhile spaces are not allowed, but instead are represented as %20 when encoded. There are other special characters that will need to be encoded.

Here are a couple of sites to help you encode:

https://www.urlencoder.org/
https://www.url-encode-decode.com/

Filed Under: HTML Tagged With: encode, url

Modify Header on Genesis Themes

September 10, 2015

The Genesis theme is a WordPress theme from StudioPress. I recently worked on a project where there was a need to redirect the URL title to another URL. Essentially, there are two separate WordPress installs on the server, one install had WordPress on the root directory, the other on a sub-directory. The URL title of the WordPress on a sub-directory needed to point to the root directory. So, here’s the fix that you need to add in the functions.php for Genesis themes.

//* Modify the header URL - HTML5 Version
add_filter( 'genesis_seo_title', 'child_header_title', 10, 3 );
function child_header_title( $title, $inside, $wrap ) {
    $inside = sprintf( '<a href="http://example.com/" title="%s">%s</a>', esc_attr( get_bloginfo( 'name' ) ), get_bloginfo( 'name' ) );
    return sprintf( '<%1$s class="site-title">%2$s</%1$s>', $wrap, $inside );
}

//* Modify the header URL - HTML5 Version add_filter( 'genesis_seo_title', 'child_header_title', 10, 3 ); function child_header_title( $title, $inside, $wrap ) { $inside = sprintf( '<a href="http://example.com/" title="%s">%s</a>', esc_attr( get_bloginfo( 'name' ) ), get_bloginfo( 'name' ) ); return sprintf( '<%1$s class="site-title">%2$s</%1$s>', $wrap, $inside ); }

Just add this piece of code to the functions.php file of your Genesis child theme.

Filed Under: PHP, WP Tagged With: header, modify, url

URL Spaces in CodeIgniter

February 19, 2014

I ran into some issues with a piece of code I wrote several years ago in CodeIgniter. I’m using names of people as part of the URL. When someone enters a name with spaces on the database, the spaces are converted to %20 in the resulting URL. The URL doesn’t look pretty and definitely not SEO friendly. It needs to be cleaned up by replacing spaces with either a dash or an underscore.

The other issue is when performing a search, the database doesn’t really know that ‘John Doe’ is essentially the same as ‘John%20Doe.’ So, I ended up using a CodeIgniter function called url_title. The function strips the spaces and replaces it with a dash or a hyphen. In the case of ‘John%20Doe’, it now displays as ‘John-Doe.’ You can also use an underscore. See example below.

Replace %20 with dash or hypen

$name = 'John Doe';
$url = url_title($name);
// produces 'John-Doe'
 
$name = 'John Doe';
$url = url_title($name, '_');
// produces 'John_Doe'

$name = 'John Doe'; $url = url_title($name); // produces 'John-Doe' $name = 'John Doe'; $url = url_title($name, '_'); // produces 'John_Doe'

Put the space before the search

Before performing a search, I use str_replace to remove the dash and put back the space so it matches the database entry. It’s essentially the reverse of what I did to display a friendly URL.

$url = 'John-Doe';
$name = str_replace('-', ' ', $url);
// perform your search function here

$url = 'John-Doe'; $name = str_replace('-', ' ', $url); // perform your search function here

If you’re not familiar with CodeIgniter, check how URI routing and url_title are handled.

Filed Under: PHP Tagged With: codeigniter, str_replace, url, url_title

  • Home
  • About
  • Archives

Copyright © 2023