Remove subfolder name from WordPress site using htaccess - php

I've moved WordPress into sub-folder named /site but the URL now shows http://www.example.com/site. I want it to show without the /site/ subdirectory.
Here's my current .htaccess code
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
How do I remove the physical subdirectory from the visible URL?

I advice you against messing up the contents of the .htaccess file. Revert the changes that you've made to this file and follow the simple procedue.
Login to the admin dashboard.
Go to Settings > General
In the WordPress Address (URL) field type http://www.example.com/site
In the Site Address (URL) field type http://www.example.com
Save the changes and you should be good to go.

According to Giving WordPress Its Own Directory in the Codex, this is what you need (works for me).
Create a .htaccess file in root folder, and put this content inside (just change example.com and my_subdir):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L]
</IfModule>
There you will also find instructions to do it by changing the URL in the General Settings, which also requires you to copy .htaccess and index.php, and then edit this last. The first method seems easier.

Try following steps:-
1)Create the new location for the core WordPress files to be stored (we will use /wordpress in our examples). (On linux, use mkdir wordpress from your www directory. You'll probably want to use "chown apache:apache" on the wordpress directory you created.)
2) Go to the General panel.
3) In the box for WordPress address (URL): change the address to the new location of your main WordPress core files. Example: http://example.com/wordpress
4) In the box for Site address (URL): change the address to the root directory's URL. Example: http://example.com
5) Move your WordPress core files to the new location (WordPress address).
6) Copy (NOT MOVE!) the index.php and .htaccess files from the WordPress directory into the root directory of your site (Blog address). The .htaccess file is invisible, so you may have to set your FTP client to show hidden files. If you are not using pretty permalinks, then you may not have a .htaccess file. If you are running WordPress on a Windows (IIS) server and are using pretty permalinks, you'll have a web.config rather than a .htaccess file in your WordPress directory. For the index.php file the instructions remain the same, copy (don't move) the index.php file to your root directory. The web.config file, must be treated differently than the .htaccess file so you must MOVE (DON'T COPY) the web.config file to your root directory.
7) go to index.php.... Change the following and save the file. Change the line that says:
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
to the following, using your directory name for the WordPress core files:
require( dirname( __FILE__ ) . '/wordpress/wp-blog-header.php' );

Related

.htaccess configuration for homepage of wordpress site to a subdirectory and other pages to root directory

I have a wordpress site live currently. I have recoded new homepage on a new wordpress installation which is under a folder main on live server.
I need .htaccess configuration which will map the homepage to new homepage without url redirect to subfolder and other pages will remain same.
Eg. when I open example.com, content of new wordpress site under main folder should be visible and other pages eg. example.com/about-us will display content of current live site under root directory.
I used this in hostgator. Note: latinstartup.com is the main domain of the account. This is the code for my .htaccess located in public_html folder. Good luck!
# Use PHP56
AddHandler application/x-httpd-php56 .php
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change exampledomain.com to be your primary domain.
RewriteCond %{HTTP_HOST} ^(www.)?latinstartup.com$
# Change ‘subfolder’ to be the folder you will use for your primary domain.
RewriteCond %{REQUEST_URI} !^/latinstartup/
# Don’t change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change ‘subfolder’ to be the folder you will use for your primary domain.
RewriteRule ^(.*)$ /latinstartup/$1
# Change exampledomain.com to be your primary domain again.
# Change ‘subfolder’ to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?latinstartup.com$
RewriteRule ^(/)?$ latinstartup/index.php [L]

Hide subfolder url in all pages Wordpress

I have installed the site in a subfolder of an existing site. When I open the home page, the url looks like this: www.nextarconsulting.com/SitoNextar/
I would like it to appear instead: www.nextarconsulting.com
I tried different solutions via .htacces but no one works!
PS: The old site (where I have the subfolder with the new wordpress installation) has the same url as the new site, so I have 2 equal link redirects after I modify the .htaccess of the new site. Can this be in conflict?
Here is my .htaccess file :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /SitoNextar/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /SitoNextar/index.php [L]
</IfModule>
# END WordPress
# BEGIN Hotlinking
# END Hotlinking
I would also like to see that the other pages of the site no longer appear on the folder path. For example: www.nextarconsulting.com/SitoNextar/contacts.html must become
www.nextarconsulting.com/contacts.html
You do this through Wordpress Settings, the index.php and .htaccess files.
Go to the General Settings in your Admin area. You will see that "WordPress Address" and "Site Address" fields will have the same URL. You need to change the Site Address option to point to your root domain, i.e. http://www.nextarconsulting.com and leave WordPress Address option as it is.
Copy the .htaccess file from the installation subfolder (i.e. SitoNextar) to the domain root folder
Copy the site's index.php file from the installation subfolder (i.e. SitoNextar) to the domain root folder, and edit it as follows:
Change this line in index.php:
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
to include the installation folder, e.g.:
require( dirname( __FILE__ ) . '/SitoNextar/wp-blog-header.php' );
Notes:
You might also need to resave your permalinks after doing this.
You still login and use the Admin area from the installation folder (i.e. www.nextarconsulting.com/SitoNextar/wp-admin)
Reference: [How to Get Rid of /wordpress/ From your WordPress Site URL](http://www.wpbeginner.com/wp-tutorials/how-to-get-rid-of-wordpress-from-your-wordpress-site-url/

Remove public_html from url through htaccess

I have a legacy project on a server where the actual framework is in a folder above the public_html folder. So the directory structure is like this:
domainname.com
app/
framework/
public_html/
index.php
Now I want to place this on our own server. This is an application created by the hosting company. The root folder is default. So now my directory structure is like this:
default/
app/
framework/
public_html/
index.php
Now he's pointing to the default folder instead of the public_html folder. That's the only difference with the old version. So I've added a .htaccess file to the root folder default. The content of this file is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public_html/$1 [QSA,L]
</IfModule>
In my public_html folder I have a .htaccess file like this:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule . index.php [QSA,NS]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule . /index.php [L,QSA,NS]
So when I go to my website it works. But when I click on a link I get: http://domainname.com/public_html/theclickedpage/.
But I don't want the public_html in my url. How can I fix this?
You may want to search for a way to make a virtual host. I know some of my webhost let me configure the vhost through my admin page. It will let your server consider the url without including the specified folder, but back in the stage it performs needed redirection.
You applied correct rule ,
but the problem is link for the solution of this issue you have to
remove public_html from
your all links and it will automatically redirect to your required
path without public_html.

Main Site Displaying subdirectory in URL

My Main site displays (mypage.com/site) and all following pages include /site as well
How do I achieve (mypage.com) and no subdirectory displaying?
I have tried Removing the /site in the Site Address URL in Wordpress settings.
But it broke my login and disables me from logging in.
what must I do to remove the /site subdirectory folder dislaying on my website?
What do I do in my htaccess file?
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
# END WordPress
I supposed that your WordPress installation is under /site folder. If it's true, you can do it:
If you already has changed the URL, on General panel, to http://mypage.com (without /site), you just need to copy the index.php (under site/) to the root folder.
After copy the index.php file, edit it, adding site/ to the path to wp-blog-header.php:
require( dirname( __FILE__ ) . '/site/wp-blog-header.php' );
The detailed steps of this process are on "Using a pre-existing subdirectory install
" at WordPress docs: http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
Have you tried to change your document root in Apache?
Something like:
DocumentRoot /path/to/your/site
I don't know if you have access to your hosting, but this would be the best solution as far as I know.
If you can't do it for yourself, you can ask to your hosting provider to do it for you.

cakePHP hosting not pointing to links

I have hosted my new website here http://cvspforcomval.site90.net/ which is a free hosting site. The problem is that I can't see the pictures in my slide, and when I enter to the navigation links I get an error.
I have changed the default webroot/index.php to:
if (!defined('ROOT')) {
define('ROOT', DS.'home'.DS.'a3503999');
}
if (!defined('APP_DIR')) {
define('APP_DIR', 'app');
and my directory goes like this
/root/
public_html/ <---webroot
app/
lib/
I'm just wondering if using the free hosting site affects the error. Or I just missed something out.
<---EDITED Added below--->
In my shared hosting site. I have setup folder in this way
/app
/public_html <---webrooot
/lib
I have the default htaccess in my public_html which is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
My suspicious is that i need to change my .htaccess. I haven't solved it yet
i am getting page not found error which is due to the anchors. You are not using proper ctp links.You have to create the anchors as
$this->Html->link(__'My Page',array('controller'=>'Home','action'=>'name_of_action'));

Categories