I have a server.php file in my Laravel project . in my computer I can command PHP -S localhost:8000 server.php so if I make an HTTP request to localhost:8000 it goes and read server.php file .or if I type this URL: localhost:8000/anything/anything it goes to read server.php file. but in my Linux server
if I type domain/anything/anything it goes to var/www/anything/anything and read index.php at there. but I want to read just server.php and pass those anything/anything to server.php file and does not count them as directory.what is the apache config to do this job?
You can use htaccess rewrite rules
RewriteRule ^anything/anything$ /server.php [L]
I suppose in your case you don't want it to match the exact string (anything/anything) so this might be the solution you're looking for:
RewriteRule ^(.*)$ /server.php?path=$1 [L]
So what the rule above will do is it will check everything that's entered after the url and pass it as GET (path variable) to server.php
Related
We have a payment link system. Here's the htaccess file inside public_html/pay folder:
php_flag opcache.enable Off
RewriteEngine On
RewriteBase /pay/
RewriteRule ^result$ result.php [QSA,L]
RewriteRule ^([a-zA-Z0-9-_]+)$ index.php?url=$1
I converted it to NGINX configuration via getpagespeed, so here's the result:
rewrite ^/result$ /pay/result.php last;
rewrite ^/([a-zA-Z0-9-_]+)$ /pay/index.php?url=$1;
While there's no problem on pending payments, the expired ones are downloaded. For example, this link opens on both Apache and NGINX servers:
https://example.com/pay/M-168102-2432
But let's say this payment link has expired or paid or something else. Not active anymore. So it is redirected to:
https://example.com/pay/result?u=M-171824-2640&status=99
There's no problem on Apache, however, NGINX downloads result.php file (no file extension
though, just a file named "result".
I can't find the problem.
I am currently working to build a small php mvc framework. in a framework i have a this folder structure.
-app
--controllers
-Post.php
-core
-logs
-public
--.htaccess
-- index.php
-vendor
in here index.php is working as Front Controller
in post controller is look like this..
<?php
/**
* Posts controller
*
*/
class Posts
{
public function index()
{
echo 'Hello index';
}
public function addNew()
{
echo 'Hello addNew';
}
}
in url, i want to remove project/public/?posts/index public/?. When i remove (public/?) and visit the url. its showing me this error message.
project/posts/index
The requested URL was not found on this server.
using public/? project/public/?posts/index is working fine. and its echo index message
project/public/
The .htaccess inside of the public folder contains:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
in project main root folder ...
i did't added .htaccess and index.php file.
in .htaccess when i add this line. url redirect to xammp welcome screen
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
I'd say you want to internally rewrite all incoming requests to the controller inside the /project/public folder. But that is not what you do. The rule you implemented (RewriteRule ^(.*)$ index.php?$1 [L,QSA]) only rewrites relative to the requested folder. No mentioning of "public" in there.
The actual setup you need depends a bit on your http host setup here. Where its DOCUMENT_ROOT points to. Most likely to the folder that contains the file system structure you posted in your question. If so you should implement a rule that rewrites all incoming requests to the /project/public folder.
Something like that, though you probably need to tweak it to match your actual setup:
RewriteEngine on
RewriteRule ^ /public/index.php?%{REQUEST_URI} [L,QSA]
You can implement such rule in the http server's host configuration. Or, if you do not have access to that, you can use a distributed configuration file (if you have enabled those for the http host), so a ".htaccess" style file. That file should be located inside the folder your http hosts DOCUMENT_ROOT setting points to. So the folder containing the file system structure your posted.
Other setups are possible, this is just one option. The point is: you need to rewrite the requests to your controller. Where the controller actually is.
I have one website, say www.example.com. So when I access "http://www.example.com/program/resources/foo.gif" it serves me foo.gif image from /usr/share/roundcube/program/resources/foo.gif, I found that in access log.
So what I would like to do is, I would like to copy that image from /usr/share/roundcube/program/resources/ to my webroot /var/www/www.example.com/webroot/img/ and write rewrite rule so that when request comes for foo.gif, it should serve from /var/www/www.example.com/webroot/img not from /usr/share/roundcube/program/resources/.
I've tried this
RewriteEngine On
RewriteRule /program/resources/(.*) /img/$1 [L]
It's working fine. But what if I want to make a rule for single image that is foo.gif ?
You can make it more generic and simpler than that.
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/override%{REQUEST_URI} -f
RewriteRule .* override/$0 [L,NS]
Now just put any file you don't want to come from RoundCube into the override folder, e.g. override/program/resources/foo.gif
There is something strange going on. I am using Zend Framework on a subfolder in a site. I have a modular structure to my website, so the links consist of module names (www.xx.com/modulename). I have created a .htaccess file for the root dir, so that all of the requests would be routed to the public dir.
When i try to access the homepage ( www.xx.com) or any module it all goes exactly as it should. www.xx.com/authentication, www.xx.com/sample or www.xx.com/deathmetalreallyrox are all working as they should. But when I try to connect to www.xx.com/admin, it crashes and BURNS!!!! It does work however with www.xx.com/public/admin/.
Could it be, that my Hosting provider has set up some sort of rule in the httpd.conf to prevent me from accessing the admin section in my hosting?
Here's my .htaccess:
SetEnv APPLICATION_ENV development
RewriteRule ^(browse|config).* - [L]
ErrorDocument 500 /error-docs/500.shtml
SetEnv CACHE_OFFSET 2678400
SetEnv APP_DOMAIN http://www.xx.com/public
SetEnv APP_PREF /public
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Fri, 25 Sep 2037 19:30:32 GMT"
Header unset ETag
FileETag None
</FilesMatch>
RewriteEngine On
RewriteRule ^(adm|statistics) - [L]
RewriteRule ^admin/(.*) public/admin/$1
RewriteRule ^(.*)$ public/$1 [L]
Help?
EDIT:
Browser error msg:
Not Found
The requested URL /admin/ was not found on this server.
You redirect anything starting with admin/ to public/admin/ first and then everything to public/whatever. So when you request /admin/, it's trying to give you /public/public/admin/, which doesn't exist, so you get a 404.
Try removing the line RewriteRule ^admin/(.*) public/admin/$1. It's already handled by the next line, and you don't want to do it twice.
It turned out, that the server was somehow configured wrongly.
As I do not have the total control over the server, I couldn't know, that there was a rule in the httpd.conf, that denied access to any folder named admin or administrator, so that when I tried to get the contents of a folder by this name, Apache first checked, if a folder by this name existed, and denied it by default.
So, the concise answer, the server was configured wrongly, didn't allow access to specific folders.
I have a directory structure with the following on localhost:
http://localhost/testing/
A directory structure exists inside of testing as follows:
/testing/public
/testing/public/index.php
/testing/public/img
/testing/public/css
..etc for the js and swf directories
A .htaccess file is inside the testing folder and the contents are as follows:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /testing/
RewriteRule ^public$ public/ [R,QSA]
RewriteRule ^public/$ public/index.php?state=public [L,QSA]
RewriteRule ^stackoverflow$ stackoverflow/ [R,QSA]
RewriteRule ^stackoverflow/$ public/index.php?state=stackoverflow[L,QSA]
I am using PHP and inside of the /testing/public/index.php file I wanted to test that the $_GET['state'] is indeed saving the variable.
When I try to test out:
http://localhost/testing/public
$_GET['state'] is not found at all BUT
http://localhost/testing/stackoverflow
does indeed echo out that $_GET['state'] equals 'stackoverflow'.
What am I missing here??? Why is it that I cannot get the state=public in the first link? Thanks for the help!
This works fine on my system, but I think you are getting into trouble by having a rewrite rule with the same name as an actual file system directory. The file-system will generally take precedence. So when you load up '/testing/public' it just loads /testing/public/index.php without running your rule at all.
Try changing the rule to this:
RewriteRule ^public_$ public_/ [R,QSA]
RewriteRule ^public_/$ public/index.php?state=public [L,QSA]
Navigate to 'testing/public_', if that prints out 'public' as expected then you will know that was your problem.