Wordpress Rewrite custom URL file name with param - wordpress

I'm facing some troubles with htaccess rewites with Wordpress
I want this URL:
https://example.com/results.php?id=xxx
To fetch this URL:
https://example.com/index.php?op=results&id=xxx
basicaly the problem is catching the first URL
i tryed this snippet
add_rewrite_rule( 'results.php?$', 'index.php?results=$matches[1]', 'top' );
It works, but an unwanted slash is added like so:
https://clients.lab/esallamlab/results.php/?id=123
Note the (/) after (results.php)
Any help please!

I do not think it has anything to do with '.htaccess' file. This is how I solved this for my website
1- Go to the admin panel --> go to settings --> permalinks
2- In the 'Custom structure' section, delete the last slash/ at the end.
3- Save changes and you should be able to see the right url
https://example.com/results.php?id=123

Related

Wordpress - URL wild card id loads root permalink

I have a Wordpress page called "Design" with the permalink "/design"
It loads as expected. What I am trying to do is to tell wordpress or my htaccess file that if I want to go to a url like:
domain.com/design/123abc
It will still load the /design permalink but keep the "123abc" appened to the url. I am not looking for a redirect. I just want wordpress to load the page and ignore everything after "/design/"
Is this possible?
Found my answer. Added this script in my child theme functions.php
24565 is the id of the /design page
function custom_rewrite_basic() {
add_rewrite_rule('^design/*', '/index.php?page_id=24565', 'top');
}
add_action('init', 'custom_rewrite_basic');

Can't access subpages in WordPress due to change of url (WP and site)

I have access to my WordPress site and the homepage, but I still can't access the subpages, it says 'Sorry! You're not Authorized to access this website!'.
I've already done the following steps:
Pasted the following in the theme's functions.php
update_option( 'siteurl', 'https://yourpageserver.com/acolade-demo/' );
update_option( 'home', 'https://yourpageserver.com/acolade-demo/' );
global $wp_rewrite; $wp_rewrite->flush_rules();
After doing this, I've got my access back for my WordPress, so I removed the codes from my functions.php. I wasn't aware that I have no access for the subpages at this moment.
After seeing that I've got no access on the subpages, I tried to paste those codes back, but still no success..
I have been searching the net for help for hours. Please help..
Open your wp-config.php and paste the bellow code at the top,
define('WP_HOME','https://yourpageserver.com/acolade-demo/');
define('WP_SITEURL','https://yourpageserver.com/acolade-demo/');
and save.
Then go to WP Admin -> Settings -> Permalink -> Save it.
Open Database and table wp_options
Then find "WP_HOME" and "WP_SITEURL" and replace it with
your base folder url ie https://yourpageserver.com/acolade-demo/
Then check your site in browser
My problem is fixed. I renamed my folder containing the wordpress files, then I also changed the urls in WP-ADMIN > SETTINGS > GENERAL. At this point I got my access removed again, so I pasted these codes back:
update_option( 'siteurl', 'https://yourpageserver.com/accolade-demo/' );
update_option( 'home', 'https://yourpageserver.com/accolade-demo/' );
Notice that the link is now 'accolade-demo' because this should be the correct link and name. Now I've got my access back including the subpages.

altering the htaccess file of my WordPress

I need help altering the htaccess file of my WordPress site to all me to add new variables to the end of every url.
Like i want to add /es/ to the end of my WordPress URLs
Please guide they way i can do it
i tried
custom paramlink like below but it did not worked
/%post_id%/es/
As was pointed out in the comments, you cannot accomplish this with .htaccess.
It looks like what you want to do is add an endpoint to your posts:
https://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint
add_rewrite_endpoint( 'es', EP_PERMALINK | EP_PAGES );
The above code will add the es endpoint to your posts and pages. Make sure you flush your rewrite rules (by visiting the permalinks settings page) after adding that line, otherwise it won't have any affect.
You could then check if the endpoint is in use like this:
global $wp_query;
if(isset( $wp_query->query_vars['es'] )) {
...
}
If your end goal is to localize your site, I recommend you using something like WPML instead.

wordpress auto generate pages from sub url of page

Hoping someone can help. I don't want to create actual pages in the backend of wordpress but i want to know how i can make it so if anyone goes to a url: mydomain.com/page/sub-url.
Then i can grab that "sub-url" and output a page with content i generate via php.
If i grab that "sub-url" and i don't want to output i can do a 404 error.
I want to try to stay away from editing the htaccess file is possible but if i need to i can.
Everytime i try search for this, i get result for creating actual pages in the backend automatically which i don't want.
I think what you're looking for is a custom rewrite endpoint, which you call 'page'. Then on yourdomain.com/page/sub-url, 'page' is the parameter and 'sub-url' is the value. You can get that value with the function get_query_var().
After applying, be sure to go to your Wordpress admin->Settings->Permalinks, and click save to flush the current rewrite rules.
Update:
Use this code to show a 404 page
global $wp_query;
$wp_query->set_404();
status_header( 404 );
get_template_part( 404 );
exit();
(source)

Duplicated permalinks on a wordpress page

First I have www.mywebsite.com/blog/ Which is another wordpress Blog under www.mywebsite.com.
Then I created a page inside www.mywebsite.com which has a url of www.mywebsite.com/blog/.
I want to change the first www.mywebsite.com/blog into www.mywebsite.com/blog2 so It won't confuse me anymore.
After changing the permalinks in the admin panel. I can't access www.mywebsite.com/blog anymore.
Is there any way to access the page of the original www.mywebsite.com/blog2/wp-admin? and view the duplicated page www.mywebsite.com/blog/?
Please comments if my question confuses you.
Thanks.
When moving your site, give the guide to moving wordpress or, in this case better, the guide of changing the wordpress url a glance.
Suppose you changed the URIs where you cannot move the files, but still can access the login page (through a redirection or something) you can recover your installation easily.
wp-login.php can be used to (re-)set the URIs. Find this line:
require( dirname(__FILE__) . '/wp-load.php' );
and insert the following lines below:
//FIXME: do comment/remove these hack lines. (once the database is updated)
update_option('siteurl', 'http://your.domain.name/the/path' );
update_option('home', 'http://your.domain.name/the/path' );
run it (once) and you are done. Test your site to make sure that it works right. If the change involves a new address for your blog, make sure you let people know the new address, and consider adding some redirection instructions in your .htaccess file to guide visitors to the new location. Delete those lines from your wp-login.php.

Resources