I have this .htaccess on my Windows dev machine and everything works fine
RewriteEngine On
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/webserv/$1 [R=301,L]
RewriteRule ^login/([0-9]+)/([0-9]+)$ login.php?par1=$1&par2=$2 [L,NC,QSA]
When I upload it on my Centos server I get the error
404 The requested URL path_to_script/login.php was not found on this server.
I cannot understand why this is. The file is definitely there and I gave permissions 777.
I have checked if the .htaccess is actually used by adding rubbish in it and getting an internal error (500) which means that it is working.
Also when I use .htaccess to make restrictions on IPs that have access to the directory it works. mod_rewrite is loaded as shown in the phpinfo() I have tried.
I am at a loss here.
EDIT
I noticed that it tries to search in the base_path appending it to the root path e.g.
/path_to_script/path_to_script/login.php
And that is why it fails. How do I solve this?
I finally solved it but in a way that I am not sure I like. At least it works. If someone has a better solution I would be glad to see it.
RewriteRule ^login/([0-9]+)/([0-9]+)$ http://host/webserv/login.php?par1=$1&par2=$2
The reason I don't like this solution is because I does not give a pretty url. It just redirects.
I still do not understand why I get the root directory appended to the request if I instead write:
RewriteRule ^login/([0-9]+)/([0-9]+)$ login.php?par1=$1&par2=$2
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.
Hello I would like to change the url generated with php my website. I've tried with .htaccess but does absolutely nothing, I do not know if I'm doing something wrong.
Right now I do not have to test server, I can only do so locally. I have installed WAMP but including the .htaccess file in the folder www does nothing, URLs continue with php variables as usual.
I have enabled mod_rewrite in wampserver. By including text meaningless in the .htaccess file fails to access by browser to localhost, that is I think the .htaccess is working.
Htaccess I have written in this way for me to rewrite the url:
RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*)$ /novedades/novedades.php?id=$1&url=$2&url=$3
#http://localhost/novedades/novedades.php?id=2&url=tren&url=tren
#http://localhost/novedades/tren/tren.php
I do not know if I'm doing something wrong, to see if I can lend a hand.
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'm using mod_rewrite to rewrite sites like "url.com/foo" to "url.com/index.php?site=foo".
The Code:
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9a-zA-Z]+)$ index.php?site=$1
If i click on a link with href="/foo" it will give me
http://url.com/foo/?site=foo
The code works at other sites on the same V-Server, i have Boilerplate installed, BUT i dont use the .htaccess of it right now to fix the mod_rewrite, so it cant be a boilerplate issue, or?
I also tried the following code:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?site=$1
That code, at least, rewrites to index.php?site=foo
BUT it still creates url's like the upper example with the unnecessary folder between.
Edit: to make sure everyone understands the overall idea:
The files are based in http://url.com (index.php, .htaccess) , so i set the RewriteBase to "/".
It should take links like
http://url.com/foo
and rewrite them to
http://url.com/index.php?site=foo
there are no folders included.
I solved it, damn i'm so stupid ;)
I have a folder called url.com/foo/ and the link im redirecting is url.com/foo to url.com/index.php?site=foo so it is always trying to get into that folder. Since i renamed the folder it is working very well.
I have been getting a similar error message on RewriteRule
pcfg_openfile: unable to check htaccess file, ensure it is readable
I also have the subfolder name similar to the redirected URL part but renaming it did not solve the problem (as suggested by Chris).
After multiple attempts, the problem was solved by updating the subfolder permissions to 755 (using cPanel folder permissions dialog) :
User: Read, Write, Execute
Group: Read, Execute
World: Read, Execute
PS: I am not sure if renaming the subfolder was actually required for this scenario since before and after the rename, error message was same.
I have developed a website.On 1 page there is a picture gallery,images are getting uploaded perfectly but as soon as i delete an image,this error comes:
*Forbidden
You don't have permission to access /fdccms/backend/project_categories/view_image.php on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.*
Deleting an image is working perfectly on localhost but i don't know the problem with server.
In .htaccess also i have included rewriterule:
RewriteRule ^view_image/([^/]*)/?(.*)$ http://fdc-int.com/fdccms/backend/project_categories/view_image.php?id=$1&del=$2
Check your folder permissions. Make sure you have read, write and execute permissions for that folder. (that would be 777)
if it's your .htaccess, try this:
RewriteRule ^view_image/([^/]*)/?(.*) /backend/project_categories/view_image.php?id=$1&del=$2 [L]
since you said fdccms is your webroot.
either way the $ is un-needed since the . matches any character.
I guess you have some trouble with your rewriteRule.
Probably ?(.*) does not work as expected. The QUERY_STRING should be added automatically, but sometimes that does not happen. I am not sure, if it does not work, if there is a ? in the Rewrite Target.
so try this:
RewriteRule ^view_image/([^/]*)/ /backend/project_categories/view_image.php?id=$1&del=%{QUERY_STRING} [L]