How to allow specific URL in WordPress - php

I need a little bit help on WordPress URL.
In Wordpress Backend, I have One page and the page slug is: listing-detail
When I try below URL into the browser it's working as per my expectation.
xyz.net/listing-detail/576905/
But When I try below URL it's giving me 404 page.
xyz.net/listing-detail/576905/abc
I have to allow xyz.net/listing-detail/576905/abc URL to call same as xyz.net/listing-detail/576905/
How can I achieve this thing in WordPress?
Can anyone help to regard this issue?
Thanks in Advance.

You can use the WordPress Rewrite API to specify new endpoints and tell WordPress what to display for them.

Related

How to use get request in page template (wordpress)

How can I use the get method in WordPress?
I'm using a page template and I want to get.
When I use the get method in wordpress it redirects me to the URL without the ?page=1.
Please note that post method is working correctly.
You should be able to use get in wordpress. It sounds like you might have a server misconfig. Checkout this SO question for information on how to make sure apache is configured correctly.

Change URL of previous posts and next posts link in Wordpress

I'd like to change the URL of the <?php previous_posts_link ?> and <?php next_posts_link ?> that are being outputted by Wordpress.
Problem:
When I am on my single page, I am getting this kind of an url:
http://example.com/post-title/2/
What I like to achieve:
When I am on my single page, I would like to get:
http://example.com/2/
So, the URL without the post title!
I don't know if this is even possible, but I'd like to understand if this is doable or not.
Could someone help me out here, please?
Get next/previous post object using get_previous_post() & get_next_post() and build your custom url.
You can create custom URLs for your pages within the .htaccess file. I found a useful link that might be able to help you out from another thread. php custom link and custom pages

How can I rename the WordPress AJAX URL?

I'm currently looking for a way to change / hide the default WordPress admin-ajax.php URL. I want to do this to remove the admin from it to prevent misunderstandings by my customers when I use the AJAX URL to read for example a file from my server. In this case, the URL has the admin prefix which is a bit confusing.
So in result the AJAX URl should looks like this: ajax.php
I've searched a bit but I can't find any helpful information. Because of this I can't show you any related code. But when I got it, I'll update my question to help other people.
Alternatively and perhaps more effectively you could leverage WP API and create a custom endpoint to process your data so that there isn't url confusion.

Show a custom URL in the header on a WordPress post

I am trying to achieve a customized url that shows in url header. Different for every WordPress post.
For example, I have posts in WordPress about different countries what I want is that when I click on a country the single post page which normally shows up like this in the browser url field:
www.example.com/2017/11/china
Should show up like this, only in header like.
china.example.com or
russia.example.com
I don't know if I can achieve this using WordPress or Do I have to play around with .htaccess file.
There are more than 200 posts and I am trying to find a way to do it using an automated script or WordPress code.
I want this link to be associated with the actual post on the WordPress site. Please let me know if it's achievable or if there is already a post on stack overflow that solves this. I couldn't find one. Thank you.
china.example.com is a subdomain, example.com/.../china is a folder. They are actually two different things. To achieve this effect though, you would need to set up a multi-site wordpress installation, and treat china.example.com as one website and russia.example.com as another

404 page redirects and SEO

I hope this is OK to ask here. I am almost ready to upload a new theme to my blog. Which after some serious consideration and research in SEO I have decided to restructure some of the pages, their child pages and to remove some of the categories.
Unfortunately this will result in various 404 results which will be bad for my site.
What I want to do is this:
On the 404 page, before it loads get last parameter of url, so for example: example.com/parent/child-page-name/
Then perform a check in wordpress using get_page_by_title().
If the page exists get the page permalink then use php header location to send 301 redirect to the new page.
if not, display 404 page with search options etc..
Is this a good way to handle this? is 301 the correct redirect?
To answer your redirect question, yes the 301 redirect is the correct one to use as it passes on the link equity from the last page.
Rather than using PHP to automatically solve your 404 problem when the new blog is launched, I'd crawl your website first and manually redirect all the old links to the new ones. It's tedious, but it will make sure nothing slips through the cracks that an automated process may otherwise miss.
A good way to do this is to crawl your site as it is at the moment, put all the links into a spreadsheet and put the new urls into the next column. From there you can concatenate the urls into a rewrite rule for the .htaccess file.
To show you what I mean, I have set up a basic sheet you can use to help you out.
https://docs.google.com/spreadsheets/d/1htHq0oeATsfrFJpAxKg0_e5dJqSmJ_idrrH-tudkuq4/edit?usp=sharing
Source: Past experience, Commercial SEO Technician for 2 years

Categories