Making ExpressionEngine .htaccess allow commenting on index.html - php

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.

Related

htaccess setup for rest api to handle directories that do not exist

I'm having a terrible time and not sure if I'm overthinking it. I'm trying to create a rest API in php (may not matter). I want to have the uri in the format /api/research/data/2020. I created the directory "research" but nothing below that. In the htaccess file, I have
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/api/research/data/$ /api/research/index.php [NC,L]
I keep getting results that /api/research/ does not exist (it's true, it doesn't). I have tried to be literal and I have tried various pattern matching. I have googled around and tried a lot of things but nothing seems to be getting me what I need.
Main question: does /api/research/ need to exist? Does /api/research/data/ ? Or if not, what might I be doing wrong?
Thank you!
UPDATE May 26, 2020: I finally got this working:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^mobile/list/?$ RestController.php?view=all [nc,qsa]
RewriteRule ^mobile/list/([0-9])+/? RestController.php?view=single&id=$1 [nc,qsa]
1) The main issue I was having was starting off with ^/ instead of just ^. As soon as I made that change, it cleared right up. I do NOT need to create any of these directories.
2) The .htaccess file needs to be at the public_html level. I had it in a subdirectory trying to match the target.
I would recommend to rewrite using wildcards and then filter the endpoints of the API in PHP:
# .htaccess
RewriteEngine On
RewriteRule ^(.*)/(.*)/?$ index.php [nc,qsa]

I need to format my URL using .htaccess file but my script not working

This is my URL
http://www.example.com/details.php?id=12&page=120.v2013-09-18.by.Acme
My htaccess script
RewriteEngine On
RewriteRule ^details/([^/]*)/([^/]*)\.html$ /details.php?id=$1&post=$2 [L]
I need to get my URL to
http://www.example.com/details/12/120.v2013-09-18.by.Acme.html
how can i change my url to above format. Please help me.
You need another rule to redirect old url to pretty URL:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /details\.php\?id=([^\s&]+)&post=([^\s&]+)\s [NC]
RewriteRule ^ /detail/%1/%2? [R=302,L,NE]
RewriteRule ^details/([^/]+)/([^.]+)\.html$ details.php?id=$1&post=$2 [L,QSA,NC]
Someone very smart once said, instead of giving a fish to a hungry man, it is better to teach him how to fish. So I won't give you the exact solution. However, I have few tips for you.
Start with some small and easy snippet from a tutorial, that definitely works. If you can make it work on your server, then you can modify it step by step to your desired form.
If you cannot make it work, make sure, you have mod_rewrite enabled on your server. You can google easily how to do that. However, some hostings might not allow you to do this at all.
It is actually possible to have cool URL even without .htaccess and mod_rewrite. Check this answer out.
Know that there are some already prepared solutions for cool urls, most PHP frameworks has them. Actually, doing any web page without any framework is a pain in the ass. You can try e.g. Laravel (seems to be the most popular one nowadays). I am using Nette and I would never ever do webpage without it again.

'404 Page Not Found' every page with codeigniter

I used this .htaccess file on my localhost:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
But when I uploaded my site to the ftp, it suddenly doesn't work. I set the base_url. Mod rewrite is enabled. What else can be the problem. My knowledge is very limited, I was already happy, that I programming part, but this server stuff is over my head. But I'm willing to learn it, so if you recommend a place to start, I'm open to that.
So right now only a formatted page comes in, with basic css settings and the 404 message. It's weird, that this message can be created in a form like that, so it means it's not a technical problem, but a settings problem. I googled around, tried more .htaccess files, but nothing works. Thanks for your help!
This is silly. The controllers must be named starting with a big case letter. So the only problem was, that I named my default controller as welcome.php instead of Welcome.php. It was hard to figure out, because it worked on localhost. So this had nothing to do with .htaccess at all. May be valuable to others, so they don't make the same mistake.
I have seen this error when people are using FastCGI - you need to add to the config.php:
$config['uri_protocol'] = "REQUEST_URI";
This clicks everything together - Might not be the answer to this issue but worth a try and others with your symptoms may find this useful.
Thanks,
//P

Help with arranging the pages of a site(Mainly to deal with the links)

There is a way I was thought to do things but I want to get a little bit advanced. To pass variables and stuff through links, i do this
http://www.fayimora.com/games.php?catID=8
That works fine but am working on a more professional site now and I think that won't be nice enough. I would prefer links like
http://www.fayimora.com/games/
I know that to achieve this I just need to create subfolders under the main folder and then rename games to index aswel.
Now the only problem is how do i pass variables? Like above i passed a variable catID with value 8. Now if i want to do this giving that i dont want to show the user the variabes been passed in the link, ow do i go about this?...
I know it might be a little bit complicated but i really need it..
I was told to look at this site >However I got stuck with this
Thu May 19 15:00:28 2011] [warn] module rewrite_module is already loaded, skipping
httpd: Syntax error on line 127 of /Applications/XAMPP/xamppfiles/etc/httpd.conf:
Thanks for the help in advance and please tell me if something somewhere isin't clear
Thanks
Here is how I have done this in the past. This uses a .htaccess file and Apache's mod_rewrite module:
<IfModule mod_rewrite.c>
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=/$1 [L,QSA]
</IfModule>
These rules essentially state that, for any path to my server that is not a request to an existing file or directory, rewrite that path to go through index.php. Thus, a request such as /games/8/ will now be passed as index.php?path=/games/8. You can then parse this path in index.php and call the appropriate controller for your view.

What's the best way to get rid of .php suffix in url strings so they look pretty? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Remove .php extension with PHP
What's the best way to get rid of .php suffix in url strings so they look pretty?
Thank you in advance;-)
Use apache mod_rewrite (rewriting rules)
http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html
Make sure your apache installation has mod_rewrite enabled (will be in httpd.conf, or one of the files linked there, mods-enabled or such) and look into how routing works in cakePHP.
Couple of tips - the rewrite rules are found in the .htaccess files (make sure you don't have a unicode BOM if the server gives a 500 error) and if you do find you need those $_GET paramters, [qsappend] on your rewrite rule should pass them along. If you still get 500s the compilation errors on regexes can be found in apache's error log, invaluable for debugging.
Might be easier to do a simple project with mod_rewrite first, to learn how it works, as the combination of rewrite and routing in cake can get pretty complex pretty fast.
Options +MultiViews
in the Apache configuration.
Here is a gentle introduction into mod_rewrite.
The best way to do so (at least for me) is:
Use just one file to receive all request. In most of the cases it will be the index.php file.
Then, use mod_rewrite rules like this:
:
RewriteEngine On
RewriteBase /the_base_dir_of_your_app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /the_base_dir_of_your_app/index.php [L]
Then, you can analize the URL using functions like basename($_SERVER['REQUEST_URI']); in order to decide what to do.
Use mod_rewrite - or start using ASP.NET MVC 2 :)
If you use a framework, like CakePHP (or any other) it will do it for you. For free. Right now.
.htaccess:
Permalinks
RewriteEngine on
Remove www
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule (.*) http://yourdomain.com/$1 [R=301,L]
Links
RewriteRule ^faq$ /faq.php [L]
RewriteRule ^donations$ /donations.php [L]
RewriteRule ^contact$ /contact.php [L]
so they look pretty?
Beauty is in the eye of the beholder. It depends when you consider 'pretty'. A lot also depends on how much you want to get away from the conventions that make a working system possible and the constraints in terms of reconfiguring your site.
While others have mentioned using mod_rewrite, or URL parsing or other such approaches I'm not a fan of these - in addition to being very specific to the type of webserver the code is running on they also break the simple 1:1 mapping beween paths in URIs and paths on the webserver's filesystem.
You could just substitute '.php' with an extension of your choice...but that hardly meets my interpretation of 'pretty'.
The approach I take is to have every script (or at least every script with is intended to be entry point to generaeing a web page) is named as index.php and exists in its own uniquely named directory. The main reason for doing this is nothing to do with making the URL look nice but rather to make the codebase more manageable - I also have strict standards about the naming and placement of include files.
HTH
C.

Categories