Wordpress/htaccess - allow access to subdirectory - wordpress

I have a subdirectory (app) I want to access that is in the root folder of my wordpress site. I have looked here:
https://wordpress.stackexchange.com/questions/20152/cannot-access-non-wordpress-subdirectories-as-wordpress-overrides-them-with-a-40
I have tried the solutions and nothing worked.
I also tried adding a separate .htaccess file to the app subdirectory that looks like this:
DirectoryIndex index.php index.html index.htm
Options +Indexes
But it didn't seem to help:
The main .htaccess I am trying with now looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/app/(.*)$ [OR]
RewriteRule ^.*$ - [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
I get a 404 error.
What am I doing wrong? If I am viewing the site on an iPhone, is clearing the safari history on the phone enough to refresh the data so it recognizes the new .htaccess? Thanks.
UPDATE
I added:
<Directory "/home/eamondev/public_html/subconscious/">
Options All
AllowOverride All
Require all granted
</Directory>
to a .conf file that gets Includeed in httpd.conf, restarted apache, but didn't help.
I also tried:
<Directory "/home/eamondev/public_html/subconscious/">
AllowOverride All
</Directory>
and it didn't work, I'm not sure if I only need AllowOverride All - either way this doesn't seem to help.
UPDATE
In a .conf file that is Included in httpd.conf, I tried:
<VirtualHost 162.241.180.99:80>
ServerName eamondev.com
DocumentRoot /home/eamondev/public_html
<Directory "/home/eamondev/public_html/">
AllowOverride All
</Directory>
</VirtualHost>
but it didn't help.
Is there any reason I shouldn't just make another subdomain on my server and host the files out of there so reaching them doesn't conflict with my wordpress site?

Use below code i think it will work.
<IfModule mod_rewrite.c>
RewriteEngine On
# Map http://www.example.com to /app.
RewriteRule ^$ /app/ [L]
# Map http://www.example.com/x to /app/x unless there is a x in the web root.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/app/
RewriteRule ^(.*)$ /app/$1
# Add trailing slash to directories within app
# This does not expose the internal URL.
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule ^app/(.*[^/])$ http://www.example.com/$1/ [R=301]
</IfModule>

Turns out, my domain hadn't propagated yet, so it wasn't possible to see/test any of the changes I was making. Before I realized that it was still propagating, I also thought to just create another subdomain and host the files I needed to from there.

Related

Wordpress (Postname Permalink) 404 error

I have a problem with my Wordpress permalink. I tried to change permalink to postname "/%postname%/". When I test one of my page, its says that 404 Not Found.
I've looking around about my problem and tried many tutorials but no luck. In my opinion, my Wordpress access seems not working but I'm not sure because I'm newbie for this. Please anyone can help me solve this problem.
Thanks In Advance
Please check you .htaccess must look like below if not remove all code and write 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
After that run below command:
1 EDIT (Change None to all)
sudo vim /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
To (press i to edit)
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
save (press :wq!)
sudo a2enmod rewrite
sudo service apache2 restart
Try replacing your .htaccess with default .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
Make sure you backup your .htaccess before using this.
If your .htaccess file were writable, WordPress will do this automatically, but if it isn't- these are the mod_rewrite rules you should add in your .htaccess file.
1- Open .htaccess file and copy the following data in that file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
After updating the file the permalink issue will resolve.
My .htaccess file was set correct beforehand, so changing the file contents wouldn't help. On my Ubuntu server I tried:
sudo apt update
sudo apt upgrade
Afterwards it worked.

Using htaccess how to serve a subfolder as a WordPress page?

What I'm trying to do is server a subfolder: /subsites/brighton/ when the url domain.com/pop-up-in-brighton/availability is visited (that url is/can be a WP page. Doesn't matter to me). The site is build on wordpress so that domain is itself the result of an apache rewrite.
I've looked at RewriteRule examples and tried to adapt them but failed miserably. Can anyone help?
Whether it needs to be a rewriterule or maybe an alias? It's shared hosting so only really have access to the htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/pop-up-in-brighton/availability /subsites/brighton
RewriteRule . /index.php [L]
</IfModule>
Thanks!
i think what you need to check is the virtual server directive, you can create a new website with it's own folder and IP.
<VirtualHost 10.20.30.1:80>
ServerAdmin webmaster#host.example.com
DocumentRoot /www/docs/host.example.com
ServerName host.example.com
ErrorLog logs/host.example.com-error_log
TransferLog logs/host.example.com-access_log
</VirtualHost>
Virtual server directive
also check this article about virtual hosts and .htaccess
.htacess and VH
You need to install wordpress in your sub directory /subsites/brighton and you can follow these instructions for using a sub directory.
http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
Then you can point to that directory from /pop-up-in-brighton/availability using mod_rewrite in the .htaccess of you root directory.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com$
RewriteCond %{REQUEST_URI} ^/pop-up-in-brighton/availability [NC]
RewriteRule ^(.*)/?$ /subsites/brigton [L]
See how that works. Replace yourdomain with your real domain.

htaccess WWW to no-WWW not working

Ok I know this hasn't been answered a lot, but I've been using a lot of various different solutions but none of them are working for me.
I'm trying to use mod_rewrite in my htaccess to redirect all www.domain.com to domain.com - standard enough.
The site is a wordpress site, and it's always worked for me without any problems using any of the following
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Or
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com [nocase]
RewriteRule ^(.*) http://domain.com/$1 [last,redirect=301]
I've tried a few other ones as well but none seem to work!
It may also be worth bearing in mind the following are also in the htaccess from wordpress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I have also checked to see if mod_rewrite is even enabled and it appears to be based on the methods in tried here How to check if mod_rewrite is enabled in php? (Christian Roy's solution)
The server is a small droplet with Ubuntu 12.10 hosted with digital ocean if that helps? I followed this guide to ensure .htaccess was activated https://www.digitalocean.com/community/articles/how-to-use-the-htaccess-file (main change was changing AllowOveride to ALL)
Anyone any ideas? I'm lost at this stage!
Thanks
Updated htaccess file contents as requested
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
**Updated with Virtual Host File **
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/wordpress/public_html
Servername domain.com
ServerAlias www.domain.com
<Directory /home/wordpress/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
It will work but you need to make sure 2 things:
You place www removal rule as the first rule before regular WP rules.
Update WP permalink settings to have blog/home address as without www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
should do it. As advised before, it should probably be done before WP-specific rewrites.

Struggling with friendly urls in wordpress

I edited the permalink settings by changing the custom structure to:
/%postname%/
Now, when I click on a page link it'll take me to domain.com/postname, but I get a 404 error. Doing some digging this shows that I need to setup 301 redirects, but I'm confused as to how to do this. I've edited my .htaccess file - it now looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mgassoc/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /mgassoc/index.php [L]
</IfModule>
# END WordPress
Can anyone help me with what I'm doing wrong?
Try doing this and see if it helps.
Add the following into your httpd.conf and re-start apache.
<Directory "/path/to/your/app">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

How come I can't move the contents of my .htaccess file into my virtual host?

I have an .htaccess file for my Wordpress website with this content.
# 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 moved this content into the Apache virtual host for my site (below) and deleted the htaccess file.
<VirtualHost *:80>
ServerName 68.183.153.223
DocumentRoot /home/david/wordpressWebSite
# 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
</VirtualHost>
However, when I attempt to restart Apache, Apache outputs an error.
RewriteBase: only valid in per-directory config files
Action 'restart' failed.
I thought that htaccess file contents could be moved to virtual hosts. What is awry?
According to the docs, RewriteBase "Sets the base URL for per-directory rewrites".
Since you're not setting up per-directory rewrites, the directive is meaningless outside of an .htaccess file for a particular directory.
RewriteBase does not work in virtualhost files.
The question you probably want to ask is:
How do I include relative paths in VHost RewriteRules?
Particularly, in vhosts, *_FILENAME returns a slash followed by the REQUEST_URI, instead of being relative or mapped to the filesystem!
Eg, %{SCRIPT_FILENAME}
In .htaccess: "assets/style.css"
In a vhost file: "/assets/style.css"
You need: "/var/www/assets/style.css"
There are several solutions:
Solution #1: %{DOCUMENT_ROOT}
RewriteRule ^/foo/bar$ %{DOCUMENT_ROOT}/foo/baz
RewriteCond %{DOCUMENT_ROOT}/%{SCRIPT_FILENAME} !-f
RewriteRule (.*) /script.cgi
Solution #2: <Directory> tags
RewriteEngine On
<Directory "/var/www/">
...
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*) /script.cgi
</Directory>
Within the directory tag, *_FILENAME is treated the same as in a htaccess file.
There may be an issue using this when the server has multiple aliases.
Solution #3: %{REQUEST_URI}
Use %{_URI} instead of %{_FILENAME} where possible
Not a real answer. Just pointing out that *_URI's won't have to be rewritten as they are not supposed to map to the filesystem, and therefore vhost/htaccess paths are the same. However, it is not always possible to use REQUEST_URI, and David Faux commented above that it is slower. Besides, thi

Resources