This should be a simple problem to solve, but I'm struggling to find a solution that works.
I have recently deployed a Flask application, which is working fine except for an issue with my .htaccess file. The application is deployed in a subdirectory (which is supposed to be reachable at mysite.com/flaskapp) alongside a wordpress blog (mysite.com) that works fine with the below:
# 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 have found that if I delete the content of the .htaccess file, the flask application works well, but none of the wordpress links beyond the front page work. Conversely, with the content above intact the wordpress install works, but every URL in mysite.com/flaskapp/* gives a 'post not found' message from the WordPress site.
As a result I assume the setup I need is to somehow not have the above rewrite rules active for any url beginning with mysite.com/flaskapp, but feel free to correct me if this assumption is wrong.
What do I need to do the the .htaccess file to resolve this so that both the wordpress blog and the Flask application work?
UPDATE: There is also a .htaccess file in the flask application's directory, in case that changes or explains anything:
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/user/flaskapp"
PassengerBaseURI "/flaskapp"
PassengerPython "/home/user/virtualenv/ratings/3.6/bin/python3.6"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END
Try adding a line like:
RewriteCond %{REQUEST_URI} !^/directory
after the other RewriteCond lines, replacing "directory" with "flaskapp" or the name of the directory to exclude.
The flask application's htaccess shouldn't need any altering.
Related
I have WordPress installed in the root folder and in a subfolder. I can access the home page for the WordPress site in the subdomain, but the permalinks does not work – error 404. I have tried to reset the permalinks, but it did not help. I can’t find any .htaccess file, so I have created one myself and placed it in the subfolder directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projects/bigsargefitness/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /projects/bigsargefitness/index.php [L]
</IfModule>
Here is a link to the subfolder WordPress site:
http://ninahortendesigns.com/projects/bigsargefitness/
I have set the database options to the above direction.
Thanks for your help.
You will need to look at a few things:
.htaccess file in the root WP site (WP1) and edit it so that WP1 doesn't catch the URLs and generate 404 errors, I'm not sure if that comment assisted, I've used this answer for a similar issue.
.htaccess file in the sub WP site (WP2) and rename it to "htaccess.old" then log into your wp2/wp-admin, go to "Settings->Permalinks" check the URL structure is as desired (it doesn't usually change) and click "Save" at the bottom of the page. This will regenerate your .htaccess file within the context of the sub-directory and you shouldn't get 404 errors when you visit sub-pages like this
Here's the code from the first link edited so that it should work with your site, although if you have additional rules, you should only insert the line under the comment.
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(projects) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
If you have custom rules, only insert these lines
# Include in the next line all folders to exclude
RewriteCond %{REQUEST_URI} !(projects) [NC]
Assuming you're a designer and are uploading examples of sites you've built, you should only have to do step 2 the next time you upload a new site to the wp1/projects/ sub-directory
Cause
Error 404 occurs when the resource or path you requested cannot be reached. In this case it's likely because URL rewrite isn't working properly, hence the permalink requests were still being directed to the requested path (e.g. /projects/bigsargefitness/your-category/your-post-name) instead of the rewritten path (i.e. /projects/bigsargefitness/index.php).
The following solution assumes you use Debian/Ubuntu, otherwise the principles should remain the same.
Solution
Firstly, ensure that the rewrite engine has been installed:
sudo a2enmod rewrite
Then, ensure that the engine is allowed for the subdirectory by editing/adding the following lines in the file /etc/apache2/sites-available/your-site.conf:
<Directory /var/www/projects/bigsargefitness/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
The key here is to ensure that the line says AllowOverride All instead of AllowOverride None.
Finally, restart your server:
sudo service apache2 restart
Let me know if this helps.
I have problems with one of my Wordpress sites at my host.
Today I installed "Traffic Stats Widget" - plugin and I followed their instructions for installation. So , I did this:
Create a robots.php file on the root directory of your blog: ie public_html/your-blog/ Paste the following code without // in it:
# #
Open .htaccess file in the same directory and paste this in it:
RewriteRule robots.txt robots.php
Make sure you have the 'RewriteEngine On' clause in place...
Make sure you have a robots.txt file, even an empty one, on the root directory
After that I was unable to access all of my subpages.
This is link of my website:
http://idealpvc-dev.com/websites/camel/
And if you try to access some of subpages you will get error 404.
I don't know why, because I restored my .htaccess file but still it doesn't work.
Also I made comparison with others .htaccess file on other wordpress sites but there isn't any differences except folder names.
Any suggestion will be appreciated.
Also, above is content of my .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /websites/camel/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /websites/camel/index.php [L]
</IfModule>
# END WordPress
Sites is located at /public_html/websites/camel
Thanks in advance
Make this as a RewrieBase in your htaccess file
RewriteBase http://idealpvc-dev.com/websites/camel/
Instead of this
RewriteBase /websites/camel/
And make your wordpress permalink Default From Wordpress Admin panel > Settings >> Permalink >>> Default
I have a strange problem with a site i installed on my server, the same exact code works elsewhere so i'm stuck here trying to figure out what is not working.
# 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
This is the standard Wordpress htaccess. Technically, the "!-d" rule should allow me to list or access any directory but in this install, it's not the case.
I have a "admin" folder and wordpress keeps kicking in and handling the admin url as "wp-admin" but thats not what i want. I already have other servers where i have a custom "admin" folder mixed with wordpress and it launches fine but something strange here seems to be hapenning.
What we have done:
Disable the rewrite engine, wordpress turns off the folder responds
Disable/Reenable the rewrite engine (to flush possible existing rules) nope
Tried to add "RewriteCond %{REQUEST_URI} !^/admin", doesn't work, WP still kicks in
Can you guys suggest anything else?
After some testing we found out that wordpress was catching all error messages even the 401 on our server. It kept showing 404 because thats the only rendered error by Wordpress.
To this end, we just put a
RewriteEngine Off
In the folder we were trying to access and blam! all of it works now!
I hope this can help others!
I have moved a site from my test dev to a live server (its wordpress) and for some reason no matter what page I click on only the homepage loads.
Think I have narrowed it down to my 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
and this line in particular:
RewriteRule . /index.php [L]
If I remove this or remove the htaccess completly I get a Forbidden 403 error.
I was hoping someone could help me figure this out?!
Very common issue is redirect plugin. Disable all plugins and post back. Have you got your website in the root folder or is it in the sub directory?
Update:
Changing the Site URL
There are four easy methods to change the Site URL manually. Any of these methods will work and perform much the same function.
Edit wp-config.php
It is possible to set the site URL manually in the wp-config.php file.
Add these two lines to your wp-config.php, where "example.com" is the correct location of your site.
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
This is not necessarily the best fix, it's just hardcoding the values into the site itself. You won't be able to edit them on the General settings page anymore when using this method.
Source
Update:
Goto
wp-config.php
and add
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
Turned out there were a bunch of random files in the root, with the FTP I only had access to the public_html. There were a number of htaccess files and other config files which we cleared out and it solved the problem.
I've been working on my localhost machine developing my wordpress site, and I'm going to export the database and import it to another localhost on another machine. The thing is, I've tried it already and when lets say you click on about it gives a 404 error not found in database. I'm using custom permalink structure /%postname%/
But when in the new localhost I change the custom to default it works. I don't want to /p?=123 at the end of my URL since I already have my links set up. Was wondering how I can set up the links to work?
you need to click on the wamp server, choose the apache menu -> apache modules then move the menu down and choose rewrite_module. You will need the server to restart for the changes to take affect.
If your .htaccess file is writable and mod_rewrite is enabled, WordPress will insert this code when you change the permalink structure. If it is not writable, WordPress will let you know to copy and past this code into the .htaccess
# 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