Got pulled in the last second because someone made a minor tweak to a WP site of ours and removed "www." (or so I am told) from the url. Now the page can only be reached by typing in wxyz.com (example). So, I speculated it was a .htaccess write and told my friend who is attached to that project about it. He agreed to try, but handed it off to me due to time constraints.
So I looked at it- for some 3hrs. An amazingly simple little problem and clearly I am missing something.
The other developer said all he did was add:
RewriteCond %{HTTP_HOST} !^kokonut\.com$ [NC]
RewriteRule (.*) http://kokonut.com/$1 [R=301,L]
But none of my code or tweaks to his would change anything, first of all. The site wouldn't ever work.
Secondly, WP has a front end system to change the url's so after this failed I thought "well, ok, I'll just go there and say "www" in front. That broke everything, the admin panel wouldn't even work anymore!
So I had to go into wp-config.php and explicitly say:
define('WP_HOME','http://wxyz.com');
define('WP_SITEURL','http://wxyz.com');
But this was just getting back to where we started! Further, without that code up there sometimes the site just won't work whatsoever.
The current .htaccess file is as written (which is DIFFERENT than his original, apparently WP overwrote it but restoring it to how it was won't do much of anything either or so it appears to me. Honestly at this point I may be running myself in circles.):
# 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
How it was when I was first assigned to "fix" it:
# 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]
RewriteCond %{HTTP_HOST} !^wxyz\.com$ [NC]
RewriteRule (.*) http://wxyz.com/$1 [R=301,L]
</IfModule>
# END WordPress
So what am I missing here? Obviously he could change it from www --> nothing without a problem, why is reverting it back so arduous?
I've never worked on this site, this server or with this group before. So this is a first. I've dabbled with .htaccess but I'm not "an expert", if I were I would certainly not be in this pickle!
Any help is appreciated.
Not sure if this is the source of your issues, but one big problem is that wordpress has a routing rule (RewriteRule . /index.php [L]) and then you have a redirect rule RewriteRule (.*) http://wxyz.com/$1 [R=301,L], which is fine, except that you're redirecting after you route. External redirects must happen before the server internally routes things. Additionally, wordpress will overwrite the rules that are inbetween the # BEGIN/END WordPress comments. So if you don't want wordpress to overwrite rules that you add, you need to include them outside of that block:
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} !^wxyz\.com$ [NC]
RewriteRule (.*) http://wxyz.com/$1 [R=301,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
Related
Long story short, I updated an e-commerce website but had to install the new static CMS system into a sub-directory (/wear). The main e-commerce store is still sitting in the root directory (/), and due to the large amount of products and SEO impact, I need to leave it there.
I would like to setup a requests for just index.php to redirect to /wear/
At the same time, if there is a request for index.php?XXXXX I would like it to still use the index.php file.
I've tried using the following .htaccess code but it's redirecting everything. Can anyone help me with this? I apologize for asking this as I know there are multiple threads, but none seemed to provide a good answer.
Attempt 1
RedirectMatch /index.php https://domain/wear/
Attemp 2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wear/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
The issue comes from your RewriteBase. When setting it up to /wear/, RewriteRule ^index\.php$ - [L] actually translates to RewriteRule ^wear/index\.php$ - [L] which is not really what you want.
I would try something like this:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.php$ /wear/ [L,R=301]
What it does is: check that the query string is empty, and if it is, redirect index.php (at the beginning of the request URI, so /index.php only) to /wear/
You will also need to make sure than mod_rewrite is active.
To do so, you can remove the <IfModule mod_rewrite.c> and </IfModule> parts. If mod_rewrite is not available, it will trigger an Error 500 as the RewriteEngine command will not be recognised.
My problem is a little difficult to explain but I think it has to do with the rewrite rules. Basically I have a script that converts a standard site to a mobile site the code is not really supported, by its dev on google code, so I figure I might get some help here I re-coded it a bit so it works with today's phones.
It works fine as long as none of the pages it must access are in a sub
so for example the site is www.mysite.com the script is in a sub-domain
m.mysite.com the script gets the pages from the main site but appear to be served from the mobile site, a example urls m.mysite.com/mypage.php
will work fine and any links on that page do work.
But if the page is in a dir like m.mysite.com/blog/myblog.php it will access that page and you will see /blog in our url but all the links on the page you click will show 404 because they all link as m.mysite.com/myblog.php not m.mysite.com/blog/myblog.php so it does not seem to know that for this page its in /blog even though it is clearly in the url why is it not in the links on the page?
Any ideas what might fix this would this be a rule issue? the htaccess is as follows.
DirectoryIndex phpmobilizer.php
Options +FollowSymlinks
RewriteEngine On
#RewriteCond %{REQUEST_METHOD} =POST
#RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ phpmobilizer.php?url=$1 [QSA]
The other issue I have is if it calls a page with a form it will not post I get 404 if I use the rules I have commented out, if I don't add them it will just reload the page no post. Maybe both problems are somehow related, my hope is some expert can help me sort this all out.
Tried to keep this as short as I could but a tad tricky to explain.
I am not very certain if it works for you. It works in my case with my wordpress page. Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?yoururl.com$
RewriteRule ^(/)?$ yoursubdirectory [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/kml/(.*)$ [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>
Cheers
Eric
God, this little problem drives me crazy and I really hope that you'll help me how to figure it out.
I searched over all previous threads and in the codex of wordpress, didn't find my exact problem.
This is it :
I've one host with a wordpress installed at the root. I've one domain pointing it. Everything is fine.
I've need now a second install of wordpress, that i've installed in a subfolder. I've a second domain, linked to this subdfoler.
Like this :
root > domain.net
root/subfolder > anotherdomain.net
If I let the "site url" setting and the "wordpress url" setting with "domain.net/subfolder", this is OK, I can access to my second site and all permalinks work.
But if I edit my site url/wordpress url in "anotherdomain.net" it renders the "domain.net" homepage without style...
I'm sure this is a question of HTACCESS but I can't find how to properly write it...
Thanks for your answers !
(sorry for my english, not my mother tongue)
EDIT : Here are .htaccess (at this state, I let them in order to access subfolder via domain.net/subfolder)
root:
# 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>
root/subfolder
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subfolder
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subfolder/index.php [L]
</IfModule>
# END WordPress
HTACCESS would be my first guess too, but another thought occurred to me: have you made sure that you are installing the two sites in two distinct SQL databases?
Assuming this is not the problem, is there any way you paste your htaccess files, so I can see if there is an issue in them?
All the config were good, the problem was with my host provider.
For the record, the htaccess for the site in the subfolder, when everything is ok :
# 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 the site and wordpress urls pointing to the new domain.
I'm wondering if anyone can help me, I'm running WP and I'm uploading and replacing files and SOME of the changes are there...
Then when I Inspect Element it's showing the OLD CSS. How is this happening? It's like it's caching my styles on the server for some reason?
This is my .htaccess file:
# Begin default subdomain redirect #
RewriteEngine on
RewriteCond %{HTTP_HOST} ^deadlineday.co
RewriteRule ^(.*)$ http://www.deadlineday.co/$1 [R=permanent,L]
# End default subdomain redirect #
# 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
Thanks in advance...
It has happened to me a couple of times. In my case, the source files have path from "cdn", so we usually purge cdn cache for changes to be reflected on the server.
Is your case similar?
I have been working on a website that is primarily PHP based. When a user visits the site stuff like http://robroscoe.ca/index.php, is redirected to http://robroscoe.ca and I am okay with this. What I am not okay with is, my webpages like robroscoe.ca/cv.php when you type in robroscoe.ca/cv redirecting back to robroscoe.ca. I am not sure how this happened and I am wondering if someone could explain to me what is going on.
# 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 think the .htaccess file has something to do with this but I am not sure how to modify this as Wordpress seems to have created this for me without me knowing it. Any help or reading materials would be appreciated.
Thanks for your time!
You problem is that you've created a PHP script that is separate from WordPress and are trying to access it through a 'pretty' URL which WordPress handles. WordPress does not know of a page called 'cv', and handles it like any other 404.
I would strongly recommend that you create the page within WP so it can manage its own 'pretty URL' structure.
If you're hellbent on shoehorning your own scripts in, then get cozy with hand-editing your .htaccess file for each one.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^cv/?$ cv.php [L] #new rule
RewriteRule ^index\.php$ - [L] #this is made redundant by the very next line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>