My working Conrete5 site recently developed a "no input file specified" problem on ALL admin pages. The root of the problem appears to be that admin pages have an unnecessary /index.php in the URL. I.E.
www.example.com/index.php/login/do_login......
If the /index.php part is removed from the URL the page will load (though all referenced files will still have /index.php hence fail to load).
I have concrete running in a sub directory but the page urls are from root e.g.
www.example.com/concrete-page-title...
This is the .htaccess file in my root directory relaying concrete requests to the concrete sub-directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.example.co.uk/$1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^example.co.uk$
RewriteRule ^/?(.*)$ http://www.example.co.uk/$1 [R=301,L]
# redirect concrete
RewriteCond %{REQUEST_URI} !^/concrete
# permit normal access to wordpress installation
RewriteCond %{REQUEST_URI} !^/news
RewriteRule ^(.*)$ concrete/$1 [L]
</IfModule>
I have pretty urls turned on, here is the .htaccess file in my concrete sub-directory (/concrete).
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
Sidenote:
cgi.fix_pathinfo=1 (have changed to 0, no change)
And the site is not hosted with GoDaddy.
The sites been for a fair while now with no updates, despite my fiddling I have had no success so any suggestions greatly welcome.
Something that worked on a site where the server's PHP had been upgraded:
in config/site.php add:
define('SERVER_PATH_VARIABLE', 'REQUEST_URI');
define('DIR_REL', '');
Related
I'm in the process of transitioning my single site WordPress installation into a multi-site. I'm trying to fix the broken CSS/JS from my main site.
I currently have two sites on my network:
http://www.example.com (primary)
http://dev.example.com (secondary)
My multi-site installation is inside of a subdirectory we will call "wordpress". So the file path looks like public_html/wordpress.
My goal is for neither site to have the "wordpress" subdirectory in the URL. Everything seems to be working except for broken CSS and JS on the primary site (the secondary site looks fine).
When inspecting the code, all of the CSS and JS calls point to http://www.example.com/wp-content/ but the files are not found there. The files will be found if I go to http://www.example.com/wordpress/wp-content in my browser. I want to hide the wordpress folder and still be able to retrieve the files.
I'm confused on how to setup the HTACCESS file. I already made some initial changes to it in order to get the multi-site within the subdirectory working. These were all following guides I found on StackOverflow and elsewhere online in regard to how to move your site into a multi-site with subdirectory and hiding the subdirectory. I haven't found anything about addressing the broken CSS/JS issue.
I figured I need to make updates to one or more of 3 HTACCESS files.
1.) public_html/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ /wordpress/index.php [L]
</IfModule>
2.) public_html/wordpress/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [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]
</IfModule>
3.) public_html/wordpress/wp-content/.htaccess
This file didn't exist but I created it. My thinking was that files are being called without the wordpress subdirectory but they need to act like they have the subdirectory included in them. For example, currently http://www.example.com/wp-content/uploads/image.jpg is broken but http://www.example.com/wordpress/wp-content/uploads/image.jpg works. I want it to be the other way around or I want both paths to work.
<IfModule mod_rewrite.c>
RewriteEngine on
# ADD WORDPRESS IF URL DOES NOT HAVE IT
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteRule ^(.*)$ /wordpress/$1
</IfModule>
I've tried adding different lines to the various HTACCESS files but none of them worked. I also not sure what line number I should insert a new rule. It's possible that one of my new rules is correct but it is in the wrong place. Below is one that I really thought would work but didn't.
RewriteRule ^/wp-content/(.*)$ /wordpress/wp-content/$1 [R=301,NC,L]
First, you should remove all the .htaccess files and keep only the one in the root: public_html/.htaccess
Second, your last rule isn't working because is slightly wrong.
You should change it from:
RewriteRule ^/wp-content/(.*)$ /wordpress/wp-content/$1 [R=301,NC,L]
To:
RewriteRule ^wp-content/(.*)$ wordpress/wp-content/$1 [L,NC]
Because you don't need the starting / and you don't need to 301 redirect. You want to keep your wordpress folder hidden and just map the requested URLs from wp-content/(.*) to wordpress/wp-content/$1
Also, this rule must be the first in your .htaccess file to have priority over following default Wordpress rules. Your final and only .htaccess from public_html/ should look like this:
RewriteEngine On
RewriteBase /
RewriteRule ^wp-content/(.*)$ wordpress/wp-content/$1 [L,nc]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I hope it helps you.
You shouldn't have to set up several .htaccess files in your sub-directories.
The only .htaccess file that need to be modified is the one located in the application root directory. In your case, it seems to be your public_html/.htaccess or your public_html/wordpress.
Now by default WordPress generates an .htaccess file in that directory which looks something like the following:
# 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
In order to rewrite your URLs, you need to add your RewriteRules before the WordPress code block.
Since RewriteRules are processed from top to bottom, if the request is first rewritten to index.php by the WordPress block, then your rule will never be processed.
Therefore your RewriteRule:
RewriteRule ^/wp-content/(.*)$ /wordpress/wp-content/$1 [R=301,NC,L]
should be enough if it's placed at the top of the root directory's .htaccess, and remove the .htaccess file in the sub-directories
Most Multisite networks are installed in the root directory of your site. This means that if your server is using example.com, then this will be the URL for your base site on the network.
If you’ve installed WordPress Multisite in a subdirectory, then you can’t use subdomains.
If you already have a single site installation at example.com, and you add another WordPress installation in a subdirectory running Multisite, then its address will be example.com/wordpress.
Any site you create on your new network will be at example.com/wordpress/my-new-site. Creating a subdirectory would be impossible here, as it would have to be at an address like example.com/wordpress/my-new-site.network Which just doesn’t work.
Specifically, I want to redirect all non-www pages to www, while also running an index.php file located in my root directory. To solve both of these problems I am using .htaccess.
I have already set up my site to run the PHP file to run in every directory. But the moment I add redirection from non-www to www it breaks.
The problem seems to be, that the multiple rewrite rules conflict with each other. Either one runs and the other does not, or the site just responds with a 500 error.
My question is, should multiple Rewrite rules be "combined" into one? Or am I just using those multiple rules wrong? (Or is it just some strange syntax thing I messed up? I have been working on this for a while haha)
Any help is very much appreciated.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,QSA]
# Redirect to www.
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
</IfModule>
I found this works:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L] #if not already index.php
RewriteCond %{REQUEST_FILENAME} !-f #only if NOT a FILE (directory / non-existent file)
RewriteRule . /index.php [L] #redirect to index.php
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*) https://www.example.com/%{REQUEST_FILENAME} [R=301,L] #redirect to https://www
</IfModule>
This cannot possibly "work" as written, as there are a number of errors:
You are missing the opening <IfModule mod_rewrite.c> directive. However, this <IfModule> wrapper is not required anyway and should be removed.
Line-end comments are not supported by Apache. Specifically, the following line will result in a 500 error due to "bad flag delimiters":
RewriteCond %{REQUEST_FILENAME} !-f #only if NOT a FILE (directory / non-existent file)
(UPDATE: If you are not seeing a 500 error response here, it's possible you are on a LiteSpeed server; not Apache? On LiteSpeed, this line-end comment appears to work as intended!)
Your external redirect (at the end) that redirects to www never gets processed for anything other than requests for directories (including the root) or real files (except index.php). This redirect needs to go first, before the existing rewrites. However, see the next point...
You are incorrectly using REQUEST_FILENAME (the absolute filesystem path) in the target URL - this will result in a malformed redirect. You could use the REQUEST_URI server variable instead (full URL-path), but note that you also have a double slash issue. So, it would need to be rewritten like the following instead:
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
Minor points:
The RewriteBase is not being used here and could be safely removed. (Unless you have other directives that use this?)
Summary
Bringing the above points together we have:
RewriteEngine On
# Redirect to https://www
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Stop here if already index.php
RewriteRule ^index\.php$ - [L]
# Only if NOT a FILE (non-existent file)
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite to index.php (in the document root)
RewriteRule . /index.php [L]
Note that this still rewrites directories to /index.php, contrary to what your comment stated.
Test first with a 302 (temporary) redirect to avoid potential caching issues.
You will need to clear your browser cache before testing.
After lots of tinkering/research, I found this works:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L] #if not already index.php
RewriteCond %{REQUEST_FILENAME} !-f #only if NOT a FILE (directory / non-existent file)
RewriteRule . /index.php [L] #redirect to index.php
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*) https://www.example.com/%{REQUEST_FILENAME} [R=301,L] #redirect to https://www
</IfModule>
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
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
I have a sales script based on codeigniter and it's working great
I built an api for it, and am using it via: http://www.mysite/api/getdata
so I want now to access this api via a sub domain, like: http://www.api.mysite/getdata
as I think the solutions is: to redirect all *.mysite.com to mysite.com and then modify the .htaccess, but I don't know is it true?
----------------------------------------Update----------------------------------------
My current .htaccess File
<IfModule mod_rewrite.c>
# Check if mod_rewrite module loaded and we can work with SEO urls
SetEnv HTTP_MOD_REWRITE On
RewriteEngine on
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^yoursite\.com$ [NC]
# RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
#RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ ./index.php [L]
</IfModule>
If you are using some kind of hosting service that lets you create a subdomain and point it to a document root, you can try creating a www.api.mysite domain and make the document root where mysite's /api directory is. That would get around the need to use an htaccess file. Alternatively, if you have access to your virtual host config, you can do the same thing, creating a vhost for www.api.mysite and point the document root to the /api directory.
If you don't have any control over that stuff, you'll need to setup the *.mysite.com to point to the same site as www.mysite and use an htaccess file. Something like this in the htaccess file in the document root should do the trick:
RewriteEngine On
RewriteCond %{HTTP_HOST} (www\.)?api.mysite [NC]
RewriteCond %{REQUEST_URI} !^/api/
RewriteRule ^(.*)$ /api/$1 [L]
I have been working on my own mvc framework to further my web app learning, but am having trouble serving static resources. I am trying to have a single entry point into the application, aka a front controller, so in my project / I have an .htaccess file that redirects all requests to the app/ folder where another .htaccess passes the request uri to index.php (in app/) who delegates the request to the appropriate controllers.
However, when I try to serve up static content, such as javascripts or cascading style sheets, I still get redirected through app/index.php. I am also getting "favicon.ico does not exist in /var/www" errors in /var/log/apache2/errors.log (maybe because of symlink to ~/www?). I do not expect to because of the following .htaccess file in the root directory of my project root:
<IfModule mod_rewrite.c>
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
# ----------------------------------------------------------------------
# Suppress the "www." at the beginning of URLs
# ----------------------------------------------------------------------
# The same content should never be available under two different URLs - especially not with and
# without "www." at the beginning, since this can cause SEO problems (duplicate content).
# That's why you should choose one of the alternatives and redirect the other one.
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
#----------------------------------------------------------------------
# Route static resources to respective files
#----------------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond public/$0 -f
RewriteRule ^.+\.(jpg|gif|png|ico|css|js)$ /public/$0 [L]
#----------------------------------------------------------------------
# Redirect all other requests to the app folder
#----------------------------------------------------------------------
RewriteRule ^$ app/ [L]
RewriteRule (.*) app/$1 [L]
</IfModule>
and here is the .htaccess in my app/ folder:
<IfModule mod_rewrite.c>
RewriteEngine On
# ensure request is not path to filename or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# redirect all requests to index.php?url=PATHNAME
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Why can't I serve static content correctly? This would make sense to me if I wasn't trying to sent all static requests to public/, which is where my css, jpg, png, js, etc files reside. But I have a RewriteCond rule in there to send the requests for such files to the public dir... Confusing?
Assuming, from what I understood, that your project structure is the following:
/
/.htaccess
/app/.htaccess
/app/index.php
/public/static.js (for example)
Here is what I come up with, hoping it'll solve your problem:
the .htaccess in the root folder:
<IfModule mod_rewrite.c>
Options -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteRule ^public/.+\.(jpg|gif|png|ico|css|js)$ - [L]
RewriteRule ^(.*)$ app/$1 [L]
</IfModule>
And the .htaccess in the app folder is unchanged.
Every request starting with public and being a file with the listed extensions won't be redirected which is done with the dash character.
The last rule allows to redirect a request to the app/index.php file.
I think the resulting behaviour is the expected one:
static files in the public directory are not redirected,
files with another extension in the public directory will be
redirected to app/index.php (maybe for some error treatment),
requests not starting with public will be redirected to
app/index.php.