htaccess - add custom rewrite to standard wordpress rewrites - php

i have a wordpress website
i have uploaded some of my php code at the root of my web where wordpress is installed.
i want to open those page directly.
they open if # www.example.com/newcode.php
but i want to open them like www.example.com/newcode (without extension .php)
the problem is when i put some .htacess code to achieve this, all wordpress pages stops and shows error404 not found and if i remove htaccess code then i cant open my own newcode.php page without extension
i tried to put this code in htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^\.]+)$ $1.php [NC,L]
but doesnt work...
this is my wordpress .htaccess (automatically created by wordpress)
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^\.]+)$ $1.php [NC,L]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
id have more files like newcode.php and some folder in which there are more code files and i want all of them to open like this
i want both wordpress pages as well as my new code page to open without any extension and i cant put newcode.php in seperate folder and make another htaccess for that specific folder

This is documented pretty clearly - especially in this case where you don't even need any regexp knowledge. Simply replace everything before # BEGIN WordPress with:
RewriteEngine On
RewriteRule /newcode /newcode.php [L]

Related

How to add .php extension for particular file?

In my wordpress website i used a htaccess code to remove php extension. Then I again used a code to add php extension.
After that all files are accessible but when I click on plugins and contactform7 from my dashboard it opens https://ecxsolution.roundabouttech.com/wp-admin/plugins without extension and string after it and shows file not found.
I am not able to see all my forms even. Can somebody tell me how should I change .htaccess file to add extension for this particular file?
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

Website homepage to show subdirectory content via htaccess

I have a Wordpress website with root located at
http://www.example.com/web
Via htaccess, when I visit that address I would like to see what's on http://www.example.com/web/about-me with the browser still displaying http://www.example.com/web.
Is it possible to achieve this via .htaccess? What I have right now is
BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php [L]
</IfModule>
END WordPress
I tried adding at the bottom
RedirectMatch ^/$ /about-me/
Without any success.
So essentially you have a website which is hosted on a sub-directory of your domain, and you want to rewrite the homepage URL to your about-me page, but without the user seeing the URL change. Your main issue is trying to use a Redirect which will change the displayed URL.
This should do it
RewriteBase /web # Dropped the / suffix otherwise the rewrites get //
## RewriteRule ^index\.php$ - [L] - # Removed because the Conditions below should be doing this?
RewriteRule ^$ /about-me [L] # Redirect homepage
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L] # dropped the /web prefix as that is managed by the RewriteBase
Results:

How to redirect or load a website placed inside a WordPress directory?

I have a WordPress website hosted at the root folder and in the same root another CodeIgniter website placed in a folder.
The CodeIgniter site is not loading now. IT shows page not found error
The URL structure will be: http://website.com - wp site and http://website.com/wi/ver1/
which means I put the CodeIgniter site in a folder wi/ver1/.
The htaccess code for the base wp site is :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And the httaccess inside the wi/ver1 directory is :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|js|images|robots\.txt)
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
Could you please try to help to solve this issue?
First of all check your site_url in wordpress project. Then change your RewriteRule . /index.php [L] with RewriteRule ^(.*)$ index.php?$1 [L] because it contains double backward slashes in your url .
if you want to load your codeigniter site, change base_url in config.php file, add your folder name that url
For example :$config['base_url'] = http://yoursite.com/folder_name/.

Redirection of website-want to use /en folder being redirected to post

I encountered a strange behaviour with WordPress website.
I have created /en folder in the root and want to have another WordPress website there.
The problems appears when I try to open mainwebsite.com/en I'm being redirected to mainwebsite.com/english-post
So, WP gives the priority to the post that is found in the main domain and it's slug begins with "en".
I tried changing the folders name to "ren" and the website in the folder than shows up nicely.
I've checked .htaccess file for some redirects and none is set.
I noticed that this is a typical WP behaviour, as I tested on some "bigger" brands that use WP and same thing happens,ie:
https://www.smashingmagazine.com/en redirects to --> https://www.smashingmagazine.com/2014/11/enabling-multiscreen-tracking-with-google-analytics/
http://vanheusen.com/en redirects to --> http://vanheusen.com/products/english_shaded_box_silk_tie/
Have any idea how to solve this?
This is my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(en/)
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Try using this rule in your main .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php - [L]
RewriteCond %{REQUEST_URI} !^/en
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
And then you need this rule below in the .htaccess inside en folder
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /en/
RewriteRule ^index\.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /en/index.php [L]
</IfModule>
# END WordPress
Let me know how this works

Wordpress - That page can’t be found

I have installed and configured on apache server wordpress (I didn't do that, I am not expert on websites). Now I uploaded my php application so root structure looks like this:
...
images
voucher (this is my application)
wp-admin
wp-content
wp-includes
When I input http://address.com/voucher/index.php into browser I got Wordpress error which contains information "Oops! That page can’t be found.". I don't know why is it trying to achieve my voucher catalog "by Wordpress system", maybe should I set some settings (.htacces or smth like this)?
Wordpress when installed uses rewrite to redirect all requests to index.php by default. If you have other dirs or files on the server you will have to consider them in your .htaccess rules.
Modify your .htaccess. Here is a sample rules that bypasses wordpress rules for your voucher directory.
#only allow the wordpress rules if it is not request /voucher.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/voucher [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Or you can do your rules this way.
#if the request is for the voucher folder, do nothing and display the page
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/voucher [NC]
RewriteRule ^ - [L]
# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>

Categories