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.
Related
Hi I am having a little problem after using permalinks wordpress, the https version of the site shows the Apache start page. On the http version, the site and all permalinks work fine. I also want to say that without using permalinks, the site on http and https works well. I am using CentOS 8
My .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
My httpd.conf
IncludeOptional conf.d/*.conf
<VirtualHost *:443>
DocumentRoot "/var/www/wordpress"
ServerAlias www.example.com
<Directory "/var/www/wordpress">
allow from all
Options None
Require all granted
</Directory>
SSLEngine on
SSLProtocol +TLSv1.1 +TLSv1.2
SSLCertificateFile /var/ssls/cazzy_store.crt
SSLCertificateKeyFile /var/ssls/cazzy.key
SSLCACertificateFile /var/ssls/cazzy_store.ca-bundle
</VirtualHost>
I tried adding AllowOverride All ”to the <Directory” in my httpd.conf file but it didn't help
I solved the problem by adding this to my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
</IfModule>
I have one zf2 application and one wordpress blog, both are different directories. (/var/www/zf2 , /var/www/blog). I want that my route example.com should point to my zf2 application and example.com/blog should point to my wordpress blog. I am using apache alias feature and it is working only for main route. example.com/blog is pointing to my wordpress blog but any other route of blog is pointing to zf2 application. Like example.com/blog/aboutus is pointing to my zf2 application and showing zf2 not found error page instead it should point to my blog page.
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/zf2/public
Alias /blog/ /var/www/blog/
<Directory /var/www/blog>
DirectoryIndex index.php
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
#Allow from all
</Directory>
<Directory /var/www/zf2/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Please find below , htaccess content of my zf2 application.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
And these are my blog htaccess configuration.
# 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 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.
I have a wordpress site running on Ubuntu with apache2 server.
I want the server to redirect all traffic from www.mysite.com to mysite.com.
I made the modification in .htaccess file to look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#RewriteEngine On
#RewriteBase /
#RewriteRule ^index\.php$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]
</IfModule>
And I modified apache2.conf to this:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Still no success.I still get the Ubuntu apache server default page for www.mysite.com. What am I missing?
I have the following code in my Apache htaccess file that is used to redirect all www URLs to non-www URLs on wordpress. This works for all URLs except the root.
For example, http://www.noshon.it/recipes redirects properly to http://noshon.it/recipes. However, http://www.noshon.it incorrectly redirects to http://noshon.it/wordpress (where it receives a 404 page).
I can't figure out why all ULRs work except for the root. Any help would be much appreciated.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.noshon\.it$ [NC]
RewriteRule ^(.*)$ http://noshon.it/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Thanks to #WebChemist for suggesting that the redirect was happening in another file. I located a file named wordpress.conf in the /opt/bitnami/apps/wordpress/conf/ directory of the Bitnami EC2 instance. This file had the following code:
# App url moved to root
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
#Alias /wordpress/ "/opt/bitnami/apps/wordpress/htdocs/"
#Alias /wordpress "/opt/bitnami/apps/wordpress/htdocs"
<Directory "/opt/bitnami/apps/wordpress/htdocs">
Options Indexes MultiViews +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine On
#RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
<//Directory>
# Uncomment the following lines to see your application in the root
# of your URL. This is not compatible with more than one application.
RewriteEngine On
RewriteRule ^/$ /wordpress/ [PT]
The rewrite was occurring in the last line of this file:
RewriteRule ^/$ /wordpress/ [PT]
I modified this file to the following and the redirects are working now:
# App url moved to root
DocumentRoot "/opt/bitnami/apps/wordpress/htdocs"
#Alias /wordpress/ "/opt/bitnami/apps/wordpress/htdocs/"
#Alias /wordpress "/opt/bitnami/apps/wordpress/htdocs"
<Directory "/opt/bitnami/apps/wordpress/htdocs">
Options Indexes MultiViews +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
RewriteEngine On
#RewriteBase /wordpress/
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
<//Directory>
# Uncomment the following lines to see your application in the root
# of your URL. This is not compatible with more than one application.
#RewriteEngine On
#RewriteRule ^/$ /wordpress/ [PT]