I have a laravel installation at same domain.com. The site is up and running. I need to install a wordpress in blog folder at domain.com/blog. when I try to install the wordpress, it's not allowing me to run the installation and says "This webpage has a redirect loop" . I installed wordpress by using domain.com/blog/index.php, But after installation I was not able to run the wordpress blog from domain.com/blog/
I have provided relevant permissions to the wordpress blog folder.I will be managing wordpress from the blog admin and laravel site from laravel section.
I have seen https://laracasts.com/discuss/channels/general-discussion/install-wordpress-in-domaincomblog but could not make it work.
Mu working environment is : Xampp in Ubuntu
Any suggestions will be helpful.
I got a solution from laravel forum. Adding the line in the htaccess worked for me.
RewriteCond $1 !^(blog)
Blog is working properly as a separate folder.
this line in .htaccess is probably your culprit:
RewriteRule .*/$ /$1 [L,R=301]
comment it out and see it that solves your problem.
This line forces everything in the public domain to go through laravel's router. You could probably leave it by writing another regex above that line looking specifically for the /blog directory, or rewrite that line to route anything that != your blog directory.
You should really leave that line there if possible.
Add below lines in .htaccess
RewriteCond $1 !^(bmcblog)
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
It will look like this
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond $1 !^(bmcblog)
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
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>
Related
I am running a website with a WordPress installation contained within a /blog/ subdirectory. The Rewrite rules I have in place currently transform correctly for the main site, but not for the Wordpress install.
http://mywebsite.com
is transformed to
https://www.mywebsite.com
without issue.
However, these URLS:
http://mywebsite.com/blog/
http://mywebsite.com/blog/title-of-article/
are not transforming into what I want, which is this:
https://www.mywebsite.com/blog/
https://www.mywebsite.com/blog/title-of-article/
Is this a Wordpress issue, or is my .htaccess wrong?
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
RewriteRule ^(blog/.*)$ https://www.mywebsite.com/blog/$1 [R=301,L]
UPDATE:
The new .htaccess, placed in the /blog/ directory, has made some progress.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/blog/$1 [R,L]
# BEGIN WordPress
<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>
# END WordPress
So mywebsite.com/blog/ is being transformed to https://mywebsite.com/blog/. Great! mywebsite.com/blog/article-title/ is being transformed to https://mywebsite.com/blog/article-title/. The issue is that the www. is not being added. They need to be https://www.mywebsite.com/blog/article-title.
Any ideas as to why the www. is missing?
UPDATE 2:
Turns out I forgot to add the "www." in the default URL in the Wordpress settings (General > Settings > Wordpress URL). With that set to https://www.example.com/blog/ and the above .htaccess in the /blog/ directory, all is now working.
It's better to manage rewrite rules separately by directories.
For blog folder, you should add the rewrite rule in .htaccess within blog folder.
If you want server-wide changes, you shouldn't use .htaccess and edit relevant details within the server configuration file.
/.htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]
/blog/.htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mywebsite.com/blog/$1 [R=301,L]
When adding .htaccess entries in WordPress directory, note that there is a section that will be automatically overwritten by WordPress.
As long as you place your own rules outside of # BEGIN WordPress and # END WordPress, the rules will stay.
Finally, you should also change your WordPress Address and Site Address within the WordPress settings (Settings > General) to use https instead.
I have the following code in my htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
# 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 avoid editing the automated code by Wordpress because the changes may be erased and I'll have to do it all again. I have another site running the first three lines of code and it's working perfectly to replace example.com for www.example.com. That's all I really need for this example.com site but still preserving the Wordpress properties.
The problem
example.com is not redirecting to www.example.com but instead displaying a 301 error.
I'm using the following lines in all my WordPress-Sites before the # BEGIN WordPress. This should solve your problem. The L (for last) is the solution
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
"I avoid editing the automated code by Wordpress because the changes
may be erased and I'll have to do it all again."
You can avoid a WordPress installation from modifying its root .htaccess file.
Simply connect via FTP, or other means and chmod your WordPress root .htaccess file properties to 0444.
Where is the conflict? I can't see any conflict. WordPress only touches the lines after # BEGIN WordPress
I'm trying to force www. on all the pages of my site.
I have wordpress install in a folder on my main site (/blog). In the /blog folder there is an .htaccess file with the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
In the main dir of the site. I have a .htaccess file that has the follow:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.sitename.com [NC]
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
RewriteRule ^blog/index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)$ /blog/index.php [L]
In wordpress is have the option set for www. The www. appears on every page except the when I go straight the the site.com/blog address
Go Settings -> General:
WordPress Address (URL)
Site Address (URL)
And set both of them to www.yoursite.com (instead of yoursite.com), wordpress automagically takes care for setting all the urls to www.yoursite.com and that's it.
If that isn't enough, you shouldn't edit the .htaccess file anyway, because anytime you save or reload your permalink settings, Wordpress will overwrite your .htaccesss (some plugins may do that as well).
If you do want to rewrite your URL, you should do it with WP Rewrite (Codex), or if you want a little more simple approach, there is a good plugin for that called Redirection (Wordpress.org Plugin Directory).
In Redirection plugin you can just set the options to *.mydomain.com/* to redirect to www.mydomain.com/* with a 301, and that will take care of your htaccess as long as you keep the plugin active.
Hope this helps :)
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
In the .htaccess of the WordPress installation (/blog/ in your case), you can add the following code ABOVE the line that reads # BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ "http\:\/\/www\.domain\.com\/subdirectory\/$1" [R=301,L]
</IfModule>
## Redirect primary WordPress URL to WWW version
Obviously, replace "domain.com" with your actual domain name and "subdirectory" with the name of the subdirectory where WordPress is installed. (/blog/ in the OP's request).
Have Option for you:
using wp-config.php add:
define('WP_HOME','http://www.domainname.com');
define('WP_SITEURL','http://www.domainname.com');
using wp-admin
Log into your wp-admin
Browse to ‘Settings’ -> ‘General’
Under ‘WordPress Address (URL)’ and ‘Site Address (URL)’ add www to the address as shown below
I have a wordpress instalation that is not redirecting urls not starting with www.
Example: http://example.com/dir/ doesn't send to http://www.example.com/dir/ instead goes to http://example.com/
How do I change the .htaccess below to always redirect to the page either using www or not?
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [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 ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# END WordPress
You should not have to modify your .htaccess; actually I would not recommend it.
Sounds like you simply have your values for WordPress address and Site address set correctly in your admin console in the Settings > General section:
Another option is to add the following 2 lines somewhere within your /wp-config.php file but before require_once(ABSPATH . 'wp-settings.php'); (and be sure not to use a trailing slash):
define('WP_HOME',"http://www.example.com/dev");
define('WP_SITEURL',"http://www.example.com/dev");
I prefer this approach because I like to keep my configuration options in code whenever possible since it is easier to maintain that way than configuration options stored in the database.
Hope this helps.
-Mike
P.S. Next time you have a WordPress question, consider asking over at StackOverflow's sister site WordPress Answers? Lots of WordPress enthusiasts over the to help out.
I got the correct answer from webmasters.stackexchange.com. This works perfectly! Thanks Ruel for pointing me to webmasters.stackexchange.
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
More like a question for http://webmasters.stackexchange.com
Well anyway, if you are using cPanel, you can do a wildcard redirect from Redirects under Domains category.
But if not, try this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com[nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc]
Works perfectly. Put this at the top of wp-config.php file:
define('WP_HOME',"http://www.example.com/dev");
define('WP_SITEURL',"http://www.example.com/dev");
I'm having an issue with a rewrite.
I have a Wordpress install in my /blog directory, but I want the Wordpress Pages to appear outside of the blog directory.
So, in my root .htaccess I added a line: (The first three lines were already there for redirecting everything to "www"
RewriteEngine on
RewriteCond %{HTTP_HOST} ^tooboss.com$
RewriteRule ^(.*)$ "http\:\/\/www\.tooboss\.com/$1" [R=301,L]
RewriteRule ^(.*)$ "/blog/$1" [L]
I then changed the display URL within Wordpress to my root URL, and altered the permalink structure to prepend "/blog/" so it appeared my posts were still in the blog directory.
Everything works fine, but I can't get www.tooboss.com/blog to redirect to www.tooboss.com. Instead, it throws a 404.
Any ideas?
For reference, here's the blog directory's .htaccess file"
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Am I missing something obvious? I feel like it's getting caught between the 2 htaccess files but I'm not sure what to do to fix it.
Thanks
Wouldn't this rule:
RewriteRule ^(.*)$ "/blog/$1" [L]
cause www.tooboss.com/blog to get sent to www.tooboss.com/blog/blog?
I think you want:
RewriteCond %{REQUEST_FILENAME} !^/blog/$
RewriteRule ^(.*)$ "/blog/$1" [L]
I'm kind of new to .htaccess myself so I might be off base here.
In response to your comment to seth's answer, try this:
RewriteRule ^/blog/?$ / [R=301,L]
RewriteRule ^(.*)$ /blog/$1 [L]
I figured it out Very annoying issue. I was able to solve the issue without moving my blog to a different named directory, but it required altering the Wordpress PHP which I didn't want to do. If Wordpress was built to handle static links in the Permalink structure I wouldn't have needed to move the install