Clean URLS not working on server. - php

Firstly I apologize if this is slightly broad of a question. I hope it is not.
On my localhost I have this htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/?([a-z]+)/?$ http://myasite.com/region.php?reg=$1 [QSA,L]
RewriteRule ^/?([a-z]{2})/(.*?)/(\d+)$ http://myasite.com/single-id.php?reg=$1&n=$3&area=$2 [L,QSA]
When I go to:
http://myasite.com/uk
I am redirected to:
http://myasite.com/region.php?reg=$1
However the URL stays the same as:
http://myasite.com/uk
Which is PERFECT. However, when I upload that to my site server the url does not retain the clean url.
I have asked the server support guys and on the live chat to which I am convinced they nothing about it. I kept getting the response from them 'The problem is the htaccess, contact a developer'
My server has ControlPanel/WHM
Does anyone know why the clean URLS are not working on the server but they are on my localhost and could someone provide steps to help check/fix this issue?

It may be something to do with your RewriteRule, so modify it to the following:
RewriteRule ^([a-z]+)$ region.php?reg=$1 [QSA,L]
Might also be worth replacing + with the exact character count you may encounter for each region, i.e. {2} :-) - Example

Please echo $_SERVER['SERVER_SOFTWARE']; just in case the server is not running the php file on nginx server. I have seen this one time.
<?php
echo $_SERVER['SERVER_SOFTWARE'];
?>

Related

server error using URI embedded images in a required file if index.php isn't in the url

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.

php file not accessible when url typed in to browser

I tried to search for this on the forums, but I don't know exactly what my issue is called. I hope this isn't redundant to another forum or a really stupid question. This is also my first post, so I read through what I need to put in this question, but please help me learn if I forgot to include something.
I FTPed a .php file over to my server into the /public_html folder which is where my index.php file are as well as everything else that I can get to show in my web browser (chrome). The file is named game-response-confirmation.php. I have the permissions for this file set to 777 on the server as well just for testing purposes (i'd like to set them back to 644 when I'm done if that doesn't have to do with the issue).
The issue is when I type in the url www.mywebaddress.com/game-response-confirmation.php into the address bar, I receive a 404 Not Found error. It says that the file was not found on this server.
To be honest, I'm not sure what other information you need to help troubleshoot this issue with me. Ask and I will provide more information.
For this, I would expect the page game-response-confirmation.php to appear as a webpage in the browser. Currently, the website is a simple echo since I needed to make sure it wasn't the php file that was creating the problem.
Thank you in advance for any help.
Look at ".htaccess" file. Perhaps there is wrong redirection inside.
For instance:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Third line obtains all URLs and sends them to unknown place. In result you get error #404.
Golka had a great suggestion. going into the .htaccess file gives some information about what is going on. It told me, indirectly, that my host was switching over the server. So I was able to investigate and figure out that they are in the middle of the migration. Because of this, I didn't have the new server information and was uploading the .php page to the old server while the domain was pointed to the new server. So of course this file wasn't available! Silly. Thank you all for suggestions and help.

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

Prefix of my domain is messing things up... How do I resolve this?

I am writing a Facebook app and for it to work properly, I need to set the Site URL inside the Application settings. The problem is that if I set my Site URL to be
domain.com
it works on my system and a bunch of systems that I tested it on. Some of my friends complain that it is not working on their system. When I looked at what the error was, it was sending me back this:
Given URL is not allowed by the Application configuration.
which is telling me that the referrer URI that I am sending it is not what it is expecting in the Application settings. So what I did was I changed the URL to:
www.domain.com
and now my friends are able to use the application and it is failing to load on my end. Does anyone know how to fix this issue? Both cases, I tested it on Windows and Ubuntu with the same browser version yet I am seeing this problem and I don't seem to understand why this is happening.
Ok I am not a fan of this solution myself but consider this a hack... This really should be fixed on Facebook end :(
Step 1: In the Facebook Site-URL field of your application just put www.domain.com
Step 2: Create a .htaccess file in the app directory and put the following text in it:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
Hope that helps someone with the same behavior.

Categories