I was digging the net and haven't found any proper solution for this issue. Basically, I want to remove subdirectory (subdirname) name from all URLs, e.g.:
http://test.com/subdirname/
http://test.com/subdirname/content/
http://test.com/subdirname/content/newpage
The website is based on Wordpress and located in /subdirname. I've got two .htaccess files, one in root directory:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !^(/var|/static)
#RewriteCond %{REQUEST_URI} !^(/index\.php|/var|/static)
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
RewriteCond %{HTTP_HOST} ^(www\.)?test\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subdirname/
RewriteRule ^(.*)$ /subdirname/$1 [L]
and second in /subdirname/ directory:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirname/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirname/index.php [L]
</IfModule>
# END WordPress
If anyone has some tips how to solve it, please advice.
You should be able to set up WordPress to display at your root domain but be installed in the subdirectory. Just change ONLY the site URL under the Settings-> General screen. Leave the subdirectory in the WordPress URL box. Then you would login at http://yoursite.com/subdirectory/wp-admin, but folks visit your site at http://yoursite.com.
Related
I read lots of discussions about this and found no solution. I have a Laravel web app and added a Wordpress blog (Blog) in a subdirectory public. This is what my .htaccess looks like within the public folder:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
And this is my .htaccess in wordpress root directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Blog/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /Blog/index.php [L]
</IfModule>
If I use the plain permalinks, everything works fine. If I use any other type of permalink it adds index.php to the URL and shows me the Laravel app. The permalinks adds the index.php in the permalinks page:
look here, currently all this is well but if i use any type of permalinks no(plain) it's not work
The funny thing is, if I choose the post name permalink with the %postname% in it, the URL is:
http://localhost:8000/blog/postname/
and I see the laravel app, but the same URL with the admin
(http://localhost:8000/blog/wp-admin/) or any other admin pages, works fine.
I really don't want to have to use ugly permalinks here.
Is there a solution?
NB - as you can see on the url, the site is currently on localhost using APACHE in kali linux
The conditions in the Laravel rewrite are probably matching. Requests to WordPress won't match a file or directory and will be rewritten by the rule:
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Try adding a condition to not rewrite for the blog directory:
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule ^ index.php [L]
I have a problem with a wordpress site as follows:
A website was built on http://example-domain.com.
I have build a wordpress site on http://example-domain.com/wordpress.
I want to delete everything in public.html folder and put a clean wordpress there.
The problem is that after I installed the clean wordpress, I keep getting redirected to the /wordpress subdirectory.
What I have tried:
Changed the site URL and home from example http://example-domain.com/wordpress to http://example-domain.com, copied a clean htaccess file in the new wp instalation.
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Before, I had 2 htaccess files, one just like the one mentioned above, that was located in the subdirectory and one in the root like this:
DirectoryIndex /wordpress/index.php
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule .* index.php [F]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
<IfModule mime_module>
AddHandler application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
Extra info: It is not a cache or cookie nor browser issue.
Update:
I was watching the Network tab in dev tools on Chrome and saw this error.
Any help would be greatly appreciated!
Did you changed the existing database urls from http://example-domain.com/wordpress to http://example-domain.com ?
Export the existing database, open in a text editor, do find-replace for the url's(from subdirectory to root directory) as mentioned above. Then import it into the new database. Once done, a fresh htaccess like this in the public/html root folder should be working fine.
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
I have an installed worpress project which is working on server_A. To transfer it, I created a zip file of all files that are in the public_html of serevr_A. and uploaded it in the server_B/mag/.
Also I've exported/imported the database in the new server and modified new credentials in the wp-config.php. Noted that, the database connection works well in the new server.
The problem is, when I open the project on the new server http://example.com/mag through the browser, it says:
Page not found
I guess it's because of that sub-directory in the new server named mag (because the installed wordpress project been on the root of the old server).
Anyway, do you know how can I make it working?
The content of .htaccess file:
# 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
I use Laravel framework and this is the content of the main (root) .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
In .htacess you need to do following change add your folder name in rewrite base and rule. Below will work for you.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mag/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mag/index.php [L]
</IfModule>
# END WordPress
Sometimes you need to change the websites url in your wordpress database via the wp_options table.
You'll see two fields ralating to those shown in the WP admin settings, edit these accordingly.
I "inherited" a website at the department I am working at that is hosted on a machine we don't have root access to. I managed to force https with the .htaccess file, but I was unable to add wordpress permalinks to it also. The combinations I tried all ended up pointing every link to the front page.
This is the .htaccess we have now (the wordpress website is in a subdirectory):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^familydogproject.elte.hu$
RewriteCond %{REQUEST_URI} !wordpress/
RewriteRule ^ https://%{HTTP_HOST}/wordpress/%{REQUEST_URI} [L,R=301]
And this is the example wordpress gave for the permalinks:
# 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
Does anybody have any idea how to combine them?
I'm probably missing something very simple. I have been through about 4^27 posts on mod_rewrite. But still can't make it work quite right.
I have two URLs both pointing to the same DNS entry. I have the standard .htaccess for redirecting a parked domain to a subfolder on my main domain. But when I go down two levels I run into problems. Here is my situation: I have MAIN domain and PARKED domain. I want every request to PARKED domain to end up at MAIN/PARKED, but still appear to the user as PARKED. So, when user enters PARKED/page, that is what should appear in address bar of browser, even though files live in MAIN/PARKED/page. I also want the browser-displayed URL to change to PARKED/subfolder/page even if the user manually enters MAIN/PARKED/subfolder/page. Here is the .htaccess in MAIN:
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
# Display PARKED domain to user for all pages in MAIN/PARKED directory
RewriteCond %{HTTP_HOST} ^(www\.)?PARKED\.?(:[0-9]+)?$ [NC]
RewriteCond $1 !^PARKED/
RewriteRule ^(.*)$ PARKED/$1 [L]
# BEGIN WordPress
#RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
To complicate matters, I have my Wordpress site located in MAIN/PARKED. I did not change any rules in Wordpress, as I wanted .htaccess to handle it all.
The .htaccess above appears to work correctly in all situations except when the user manually enters my 2-deep example above: MAIN/PARKED/subfolder/page or just MAIN/PARKED. Then I receive a 404. If you enter PARKED/subfolder/page, it behaves perfectly.
TIA for any words of wisdom.
Michael
# BEGIN WordPress
<IfModule mod_rewrite.c>
# tell mod_rewrite to activate and give base for relative paths
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?PARKED.com$
RewriteCond %{REQUEST_URI} !^/PARKED/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /PARKED/$1
RewriteCond %{HTTP_HOST} ^(www.)?PARKED.com$
RewriteRule ^(/)?$ PARKED/index.php [L]
# for main domain
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress