URL Rewriting in PHP using Wordpress - php

I have to continue on a project that has been developed by someone else. It is a web portal developed using PHP and Wordpress. I am using the code uploaded on localhost.
I had a fundamental question regarding URL rewriting in PHP. I have a link on the front page which says
a href="<?php bloginfo('url'); ?>/search?refer=registered&link=registered
But when I click on it, it gives a 404 error.
How do I set the URL mapping "search" -> "wp-content/themes/mytheme/page-search.php"?
[UPDATE: I found the solution myself. It had to be done through Wordpress by creating templates and setting the URL to point to the corresponding template file.]

wordpress build in url rewriting is in backend after you login /wp-admin/
go settings>permalinks where you can choose the re-write rules and click save button.
wordpress will then auto write a .htaccess file (this file is for url rewriting )
with the rules created in it.
if you find rewriting isn't working (eg, returns a 404 page) then u need to make sure your server has opened the url-rewrite mod for urlrewriting.

Related

Url redirection for custom post types - wordpress

So i have created a plugin that gets data from a API and creates posts. For example posts urls are similar to following structure .
https://sitesite.net/invite/username
About 100 posts are created this way and the only thing differs is the username. I want to redirect all
urls with /invite to a certain another url.
What is the best way to do this? Please consider that i'm new to wordpress.
So far i've tried some plugins like Redirection plugin and SEO Redirection Premium plugins. But i could not find a way to redirect all the urls with /invite in the url to another url. Both these plugins can set the source url and redirect to another url. But it's not practical for me as i have 100s of urls.
How can i redirect all my urls to another url .
The best way is to do it directly in your .htaccess file in the root folder of your Wordpress installation.
The following rewrite rule will redirect all pages in your invite folder to the same page in another folder called newfolder:
RewriteRule ^invite/(.*)$ /newfolder/$1 [R=302,NC,L]
Note the R=302 - make sure you use this for testing and only change it to a permanent 301 redirect when you are sure everything works!
(The .htaccess is not a Wordpress file, standard file on your web hosting. But if you’re not familiar with it, it’s a very important file to make your site work, so check back with us if you’re unsure of anything before you change it and always make a backup before ANY changes to it!!)

rewrite URL in Wordpress using htaccess

Hi I need to rewrite URL in Wordpress.
I have a website where pages are created thanks to data loaded from JSON files.
These data allow me to create custom links that send the parameters via the URL.
I set the permalinks with /% postname% /
Example:
https://example.com/postname/?lid=16036&name=John&st=2019-2020
I need to transform in
https://example.com/16036/John/2019-2020.html
To do that the rule is
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /postname/?lid=$1&name=$2&st=$3 [L]
Added in htaccess but nothing changes
I use a plugin "Admin Tools for Wordpress" that allow me to change htaccess
The support says:
I don't think that you are on the right path. It sounds like you're trying to convert
https://example.com/postname/?lid=16036&name=John&st=2019-2020
to
https://example.com/16036/John/2019-2020.html
in the HTML output of the page.
Apache Rewrite cannot do that. And before you ask, no, Admin Tools has nothing to help you with that nor can it possibly have such a feature due to the way WordPress pages are generated (there is no document buffer like there is in Joomla)
Can anyone tell me if there is any way to do this?

Change Startup Page of a WordPress website

I have an installed WordPress website.
I'm working on the site, therefore, I want to show a constructor page for the internet user. I have created a page which called first.html and I change the .htaccess file like below
#Alternate default index page
DirectoryIndex first.html
Now when I enter my domain name on the browser I can see the first.html. This is working properly.
I'd like to see my changes by entering the domain and page name on the browser like
www.mydomain/index.php
or
www.mydomain/wp-content/themes/XXXTHEME/index.php
However, my theme pages don't work.
How can I achieve to do this?
Instead of making changes in .htaccess, I'd suggest you to use this plugin : https://wordpress.org/plugins/maintenance/
Simply name your html file "index.html"
Web servers most commonly parse the index.html file firstly (unless told otherwise) and if it is not found, it proceeds to index.php
This also allows you to simply change that ".html" part to ".php" to see the website you are working on, without installing plugins that clutter your database or making unnecessary changes to your .htaccess file.

WordPress page is also a directory

I've got a WordPress page where the permalink is /foo.
I'm hoping to add a new HTML page (non-WP) at /foo/bar, but when I created that folder via FTP, obviously the original /foo page started showing an empty directory, instead of the old WP page.
Is there any way of combining the two, so the index of /foo is the WordPress page and the index of /foo/bar is a non-WP HTML page?
Many thanks!
The HTTP request first resolve the folder which you placed inside your WordPress installation. So there is no direct way to achieve this becuase your sub-folder name is same as the page URL.
You need to rename your folder-name/page permalink to make this happen.
Here is some suggestions,
WP Page and Subdirectory with same name
Page URL not working due to physical directory
Also please ask WordPress related question here: WordPress Stack Exchange

Url rewriting, xyz.com/questions has to redirect to somequestions.com/questions, via .htaccess

I am PHP developer recently got into Drupal development. But I am novice to URL redirecting etc issues. My issue is, I have a website already like xyz.com running on a hosting server. Recently I developed another site, which should be displayed as a subdomain like when user types xyz.com/questions automatically it has to redirected to somequestions.com/questions.
I searched the web and found some results and found that it is URL rewriting but I am unable to set it.
EDIT 1
How to mask the url with the initial URL that I have given. i.e., after entering xyz.com/questions it has to redirect the somequestions.com/questions but URL in the address must remain same.
I presume you need 301 redirection i.e Moved Permanently.
Add following line in your .htaccess file under xyz.com root directory:
Redirect 301 /questions http://184.133.111.012/questions

Categories