I am having a strange issue that I have never encountered in the past 10 years, please help.
I am working on a very simple site for a client, they have a shared host LAMP stack, I am using an .htaccess file like this...
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?p=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?p=$1
So I can access pages like domain.com/contact and it will go to domain.com/?p=contact pretty straight forward, however on the index page, domain.com it will not parse the PHP correctly, if I view source I can see my actually PHP code un-parsed on this page, all the other pages work except for my index page, any ideas why this would happen?
It worked fine on my localhost
Update
I can access domain.com/index and domain.com/index.php and they work fine, it is just when I access domain.com that it does not parse correctly
It looks like the server's setup is messing with DirectoryIndex option - it tries to find the "closest" file, but does not run php engine for it. Yes, it sounds "weird", but try to add this string to .htaccess:
DirectoryIndex index.php
ps: and another thing I wrote in comments - one RewriteRule is enough: RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?p=$1
Related
Struggling. Help!
In index.php:
require "cachedPages/home.html";
If I visit: https://websiteaddress.org/index.php then it works fine.
If I visit: https://websiteaddress.org then I get an internal server error.
I guess it's a .htaccess thing. All I have in there is some cpanel php72 code and:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
DirectoryIndex index.php
It seems there's some difference between how index.php is called if you call it directly as opposed to .htaccess calling it for you?!?
Any ideas?
Thanks in advance.
If you don't have one of the following options in your .htaccess then Apache won't know which file to default back to:
DirectoryIndex index.php
FallBackResource /index.php
Also I'd recommend installing mod_rewrite as well. It's handy for other reasons.
Well, I've managed to sort the problem, but it's a pretty weird situation that no-one else will probably ever experience. Here goes...
If the user lands at:
https://websiteaddress.org rather than https://websiteaddress.org/index.php
and that page (php) requires another page,
which has images that are embedded as URIs rather than linked src files.
Then, the first URI causes a server error.
If I replace the
img src='data:image/jpeg;base64,/998a9g98ahg...etc'
with
img src='path/to/file.jpg'
on the first instance of a jpg then it all works fine.
All the later URIs are fine, it's just the first instance!
It all works now, with this workaround; and the situation is so unique and bizarre that I doubt this thread will be of use to anyone else. In fact it's so edge-case that I can't be bothered investigating it any further myself.
I got my site setup and i've got a news system. On my old hoster it worked and now I changed my hoster and it dont work anymore.
Basically: https://www.xxabcxx.com/news.php?newsid=1 to
https://www.xxabcxx.com/news/1
My current .htaccess file looks like this:
RewriteEngine On
RewriteRule ^news/([^/]*)$ /news.php?newsid=$1 [L]
I'm only getting a white site with no code.
I already tried to view the GET via
print_r($GET);
It only shows Array ().
Anyone know how to fix it?
I'm creating a basic routing system, so my URL's would look like this:
www.domain.com/index.php/controller
Only problem is, when I go to that address, I get a 404. Is there any way to overwrite this with PHP (without using .htaccess)?
the index.php file would need to be your bootstrap file that would load the controller depending on what's being requested to it, but without using mod rewrite the url would be something like:
www.domain.com/index.php?url=controller
I've set up something like this before - In mine I had to have apache do redirects with mod_rewrite: mine sends www.domain.com/controller to www.domain.com/index.php?route=controller - should be similar to what you're after I think.
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\?*$ index.php?_route_=$1 [L,QSA]
Hope that helps.
I've got a really quirky issue going on with ExpressionEngine. I've got a live test site here.
Essentially, if you attempt to comment on the index's 'Question of the Day,' you get a proper redirect, but the comment never gets to the database.
If I remove my .htaccess and set the site's index page in my control panel to index.php, then all is well. But with the .htaccess and index.php removed, things go haywire.
Here are the comments of my .htaccess file:
RewriteEngine on
RewriteCond $1 ^(weblog|member|search|site|rss|search|contact|show|commentary|include|about|blog|tags|preview|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /skad/index.php?/$1 [L]
Any tips to troubleshoot this or ideas where I could be going wrong? If it's any help, you can see a screenshot of my folder structure.
Thanks so much for any answers or simply help that you can give.
More: Also, here are headers for a successful post on a blog entry and a failing post on the index.
Update: I did recently find something else strange. With identical backend settings:backend settings http://droplr.com/1sMXc9+
And identical code:identical code http://droplr.com/1sN09A+
I get http://localhost:8888/skad as one form action and http://skadaddlemedia.com/v2/v2/index.php as the other form action.
At this point, I'm completely lost as to what is going on.
the "?" after index.php in the RewriteRule suggests that you are on a server running PHP as a CGI script and thus requires the "forced query strings", correct? This may be ancillary to the problem in the question, but it can complicate things to have this requirement. Looks like you're hosted at Site5... I have no experience with them but you might try the workarounds suggested here: http://expressionengine.com/wiki/Workaround_for_Forced_Query_Strings/
Try changing [L] to [L,QSA] to see if it helps.
I'm not sure but i think that CI and EE are pretty much the same as to the way the htaccess works so this may help you out. It is by a CI guru named Ethan, can't remember the last name, but he is very active in the CI community. Anyway the way that your HTACCESS file is has really been abandoned the new way to do it is a lot easier and you don't have to state your excluded folders it is the best thing since sliced bread for users of MVC or any frameworks i just love it.
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
i can gurentee you that if it is a htaccess issue this bugger will fix it but the bext thing is you dont have to do a thing to it just drop it in and you never have to edit it again i swear by it. so freaking good like fried chicken in the summer yummy!
remember test it first by just dropping it in place of your current one you wont need all that crazy other stuff you got there in yours promise.
I'm writing my own url shortener. I'm done with everything such as creating short urls. But when I try to browse htt p://example.com/rtr93, I get a 404 error. But http://example.com/index.php/rtr93 works find and shows the relevant page (I'm not redirecting to a new url. I'm just getting the relevant record from database which has a column short_url).
I'm using PHP and syfmony 1.2 if that helps. I think I need to properly setup .htaccess file. But I don't know where to get started.
Something like this should work:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ /index.php [L]
You may want to make the regex more specific if you're planning on hosting other things on the same domain.