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
Related
I'm a new user and frankly, I haven't got a clue what I'm doing at this point. I'm figuring things out slowly but surely and this site has so far been a gold mine for me... So, let's see if we can make this work.
So, my website has a WordPress installation within the root directory to allow me to have a blog; WordPress is installed solely for the blog and this is in the public_html/wp folder. Everything within the wp folder is WordPress.
Now, when I write a post, the permalink is my-website.co.uk/wp/post-title.
The .htaccess file rewrites this permalink to my-website.co.uk/blog/post-title.
This is great, looks much better but the problem is, when WordPress auto-shares the posts, the /wp/post-title permalink redirects to homepage and not to the relevant blog post. This means, whenever someone clicks on the shared link, they're taken to my homepage (sorry if I sound like I'm dumbing it down).
Now, in the public_html folder, I have one .htaccess file which is as follows
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(.+?)/do-not-touch.php do-not-touch.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.htm -f
RewriteRule ^(.+?)/?$ $1.htm [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]
RewriteRule ^blog/([0-9-]+)/?$ blog.php?page=$1
RewriteRule ^blog/([A-Za-z0-9-]+)/?$ blog.php?slug=$1
RedirectMatch 301 ^/tenants.htm /information-for-tenants.htm
Then, in the WP folder, we have another .htaccess file:
#+PHPVersion
#="php70"
AddHandler x-httpd-php70 .php
#-PHPVersion
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp/index.php [L]
</IfModule>
# END WordPress
My theory (remember, I have no idea what I'm doing) is that the second .htaccess file redirects the /wp/ permalinks up to the public_html file index (shown by the RewriteBase /wp/ RewriteRule ^index\.php$ --- Not sure what the \.php$ does) whilst the first .htaccess file rewrites the /wp/post-title to /blog/post-title (shown by RewriteRule ^blog/([0-9-]+)/?$ blog.php?page=$1 and RewriteRule ^blog/([A-Za-z0-9-]+)/?$ blog.php?slug=$1).
Finally, in my WordPress admin permalink settings, the selected permalink is shown as my-website.co.uk/wp/sample-post/.
All permalinks are my-website.co.uk/wp/[customisable] -- In other words, it doesn't allow me to alter the /wp/ section of the permalink.
I could really use some help. I need to redirect wp/post-title (whatever the title may be) to blog/post-title instead of /index.
As a result of the redirect, search engines fail to crawl my blog posts (I think?).
This is my website blog: https://www.harryalbertgroup.co.uk/blog
And this is the WP permalink: https://www.harryalbertgroup.co.uk/wp
Thanks in advance.
(Note: This website was built for me. I've been slowly fixing all of the issues I've faced so far. We're slowly getting there, it's really just the sharing features that I need to fix now, from what I can see)
I have a problem redirecting links using htaccess rewrite. Originally I had only the Rewrite Rule part without the WordPress code underneath and it was working fine. Now, after I tried to add a permalink using Wordpress, the link is giving me a redirect loop problem.
Essentially what I want to do is allow the viewers to go straight to 'www.example.com/blog' when they type 'www.example.com'
I think I am missing something because I thought that the rewriteRule would stop the moment
RewriteRule ^$ /blog [R=301,L]
is processed because of the [L] flag and then other RewriteRules would not be looked at. Can someone help me understand how the server actually go through the steps of the code below?
RewriteEngine on
RewriteRule ^$ /blog [R=301,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
You need to put the line:
RewriteRule ^$ /blog [R=301,L]
In the htaccess file in your document root, not in the /blog directory.
I am in the process of moving my current static site to Wordpress, using the same domain name.
Both old and new sites have their content in the root folder and also have identical file names, but on the new (Wordpress) site, I have removed the .php extension that exists on the current site and added a trailing slash, as per Wordpress permalinks.
So I need to redirect all the old pages (for example):
/contact-us.php -> /contact-us/
I have tried the well-documented options such as (and variations on this):
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.php$ /$1 [R=301,L]
But this seems to be conflicting with the Wordpress .htaccess rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
When I try to access www.site.com/contact-us.php, I am getting either an infinite loop OR a redirect to www.site.com/index (no .php, no trailing slash), which Wordpress displays as a 404 page.
I have tried with and without the first set of Rewrite conditions (as I see they are duplicated in the Wordpress rules), and also placed my rule before and after the Wordpress rules. No joy. I've also been Googling for the last few hours but no one seems to have addressed this specific problem. I do usually find what I am looking for by searching, so it's in desperation that I'm actually posting (and which is why it's my first post!)
If anyone can help out, I would be very grateful.
It appears you will run into loops when trying an .htaccess redirect because of the php suffix. Maybe someone else knows a solution.
But try a plugin called Redirection « WordPress Plugins. Out of curiosity, I tried a redirect from contact-us.php to contact-us/ and it worked fine. The plugin redirects via php rather than writing to .htaccess, and that may be the difference.
I use the plugin all the time to mostly log 404's and do a few redirects. It doesn't take too much site overhead.
Be sure and set Options to not do "URL Monitoring," as that will set up automatic redirects to to posts/pages that have their permalinks manually changed. And set your 404 logging to a day or two, because the logs can quickly get big and result in huge database tables.
Try using this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Rewrite /something.php to /something/
RewriteRule (.*)/(.*)\.php$ $1/$2/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This method would rewrite:
/contact-us/test/hello.php -> /contact-us/test/hello/
If you don't want subdirectory rewriting replace line 6 with:
RewriteRule /(.*)\.php$ /$1/ [R=301,L]
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
We have a WP install in the root of our server and its running great.. but, we just installed another app in a subdomain. Now, I can view the index.php of that app but cannot do anything with it.. the htaccess rules in the root (from WP base install) are effecting the requests.
So, how to I eliminate the WP htaccess file from effecting the subdomain?
Here is the htaccess contents for the root (WP install):
<IfModule mod_rewrite.c>
RewriteEngine On
# BEGIN WordPress
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>
And for the htaccess in the subdomain:
RewriteEngine on
RewriteCond $1 !^(index\.php|css|stylesheets|js|images|user_guide|favicon\.ico|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I've search everywhere online and tried a couple samples I found.. nothing has worked.
Any help is greatly appreciated !
Thanks
UPDATE:
It seems that maybe Wordpress is not the culprit.. out of curiosity, I removed all lines in the WP .htaccess file.. and the app in the subdomain was still not working. Its rewrite rule must be wrong..
So, it is the second rewrite rule that is not working. If I type in /index.php?about then I can see the about page.. but it should display by going to: /about
WP is also the culprit (you have two problems).
I can fix the first .htaccess problem because WP is predictable. You want to put this before the BEGIN WordPress section:
RewriteRule ^subdir-name/.*$ - [PT]
That grabs any requests to your subdir and Passes it Through (PT) so that it is not hijacked by WordPress.
The problem in your second .htaccess is that it seems to be assuming it is still in the root directory. For this one, I can't be sure without seeing the layout of your app, but the / before index.php may well be wrong. Are you sure that the paths in the second file match the new layout of your files?
Um... should this work? For sub-directory "office" - cheers :-)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^office/.*$ - [PT]
# BEGIN WordPress
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>