Laravel remove public route AND disable it for accessing - php

I am using Laravel 7 within my last project.
I used the same approach on all my Laravel projects to remove the 'public' from the route:
- create a .htaccess within the root folder and add:
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
I agree, that this method is all around the google and also works locally. Everything perfect until here.
The problem is that I made a facebook ad campaign on this project which points to the homepage (/) of the website and also added a 'Book Now' button with a link to it. The strange thing is that the link from Facebook ad, points to mywebsite.com/public even I specified only mywebsite.com so I just tried to manual access that route with public, and it worked.
So looks like my website's homepage is / and /public/ in the same time.
I want to be accessible only on / and disable the 'public'. Maybe if it's still specified, to be redirected to /.
I also read about that kind of fix to rename 'server.php' to 'index.php' and copy the .htaccess from public to the root, but there are a lot of negative advices not to do this for security reasons.
What would be the proper and also secure way to achive this ?

Related

.HTACCESS RewriteRule not working as expected

I have a magento website, that is currently operating. Within a subfolder of this site, I have placed a 3rd party application that also has its own HTACCESS file to handle routing for its application.
When I access the folder http://example.com/somefolder the screen I expect shows up, but when I navigate to http://example.com/somefolder/newroute, I instead land on a magento 404 screen.
I have traced this to the magento htaccess file, in all cases, unlesss the path physically exists the rewriterule will always send the request to the index.php - this explains why Im getting there.
To fix this issue, I wrote a little rewriterule which I placed in the htaccess file of the magento store. The goal was to add an exception to any request that came through and contained any reference to my subfolder. The thought is now it should hit the path its supposed, then hit the htaccess file, and then route me to where IM supposed to be in this other application. Unfortunately it doesnt seem to work, after adding the rule I end up the same place - magento.
Here is what I've written:
RewriteRule ^(.*somefolder.*)$ $1 [L]
Im not sure what could be going wrong, as I think the approach seems pretty straight forward. Any ideas on how to remedy this situation?
Thanks.
Here is Your Simple Answer.Also Used By me on my site.
RewriteCond %{REQUEST_URI} !^/(yourfoldernameHERE)$

Accessing CodeIgniter app from sibling subdirectory

I'm having a scenario where I had to deploy multiple directories for different languages. Development has initially centered on one of those languages, and just one part of the whole site is a small CI app.
I'm trying to avoid copying the whole app for the several other languages, and redirecting to it with an .htacces. The latter is working fine, but CI returns a 404 error when accessed from a URL different to the real one.
My best guess is that certain configuration files must exist with unique properties that configure the additional root URLs, but I don't know where to start (and Google didn't come up with a similar scenario).
File Structure:
public_html/
lang1/
app/
(the actual CI app)
other static stuff...
lang2/
app/
.htaccess (redirecting to /lang1/app/)
other static stuff...
lang3/
...
Additional info:
The $config['base_url'] is set to http://.../lang1/app/.
The .htaccess:
RewriteEngine on
RewriteRule ^(.*)$ /lang1/app/$1 [L]
I was able to accomplish this by my own. For those who might find this question in the future, these are the steps to access your application from a different directory. Considering the scenario introduced in the question above, the following example will work for the deployment of of a ghost version of the app in the lang2 directory:
1.- Copy only the index.php file from the root of your CI installation (from lang1/app/index.php) to the lang2/app/ directory.
2.- Edit the following lines:
$system_path = '../../lang1/app/system';
$application_folder = '../../lang1/app/application';
//Even if the documentation suggests the necessity of a _full path_,
//this works perfectly well for 2.1.0
3.- Add any configuration you may want to have set explicitly for said subdirectory, these will be set to $this->config, replacing the values set in the config file in your base application:
$assign_to_config['lang_version'] = 'lang2';
4.- You have to set a proper base_url. In this case, we could reuse the lang_version config we just included. This way, we can forget about this line in the next languages we need to create.
$assign_to_config['base_url'] =
'http://www.example.com/' . $assign_to_config['lang_version'] . '/app/';
5.- Create an .htaccess file inside lang2/app to make sure that any static assets (js, css, images) accessed by the HTML are get from the actual assets folder inside the original app directory, like in lang1/app/assets:
RewriteEngine on
RewriteRule ^assets/(.*)$ /lang1/app/assets/$1 [L]
6.- Add to this .htaccess your usual rule to keep your URLs friendly, but this time directing all traffic to the ghost copy of your app:
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /lang2/app/index.php/$1 [L]
7.- Grab a beer or any other beverage you drink to celebrate success, always respecting your local laws. Profit. Your controllers will have to read the config('lang_version') value to present the content in the proper language to the user. You may use the included language helper for that, or any other solution you prefer.
Why would you do this? Theres a thing called i18n.
http://codeigniter.com/wiki/CodeIgniter_2.1_internationalization_i18n/
Why not use this? Didnt copying the app folders seem a bit tedious to you? Theres a language helper for a reason.
I hope this helps.

My Codeigniter site works on localhost but not on web server? 500 internal server

I have tested my website on my localhost and it is working fine and all the views/controllers and models are tested.
So I thought I would put it on my webserver and test it there, the website displays however when doing functions like
For example registering or loging into the website does not work:
I checked in firebug it is saying
500 Internal server error
Here is my site, please could you have a browse through the pages , even try registering if you like.
Another thing I noticed on the failed pages is that my favicon is changing to the root domains favicon.
Here is my actual website, its in a sub domain.
Could it be my htacces
Here is the code in it:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
I dont understand why It works on my localhost but not on a dedicated server.
They were both Apache windows servers.
Thanks, for your time.
I think the problem is with your routes. All your pages are with in the domain
http://www.iiios.eu/midas/site/register
But on registering or login it goes to
http://www.iiios.eu/midas/register
without the site in the middle and CI doesnt know how to transfer control to the route. You might wanna check your forms open and action atr for register and login form.
Update
This is your form tag. Check whether you have the method create_member on register class which is in midas directory. My guess is that you have accidentally missed the site there.
I think it should have been
"http://www.iiios.eu/midas/site/register/create_member"
This might be a problem with the routing, see if the referencing to the routes, like when registering, are correct or if you defined routes in the config.php. Is the base_url() defined correctly? Also on the homepage in the sidebar you reference a non-object property.

how do i hide /magento/ in my site's url?

A site has an existing system (lets call it mysite)
and the client asks to put in magento.
My directory structure goes something like this:
ROOT
-index.php (this is the app's main controller)
-.htaccess
/blog (runs wordpress)
/assets (current system's media folder)
/magento (this is where all magento files go)
Problem is if I set up magento and specify in the installation that base URL is http://example.com, magento loads up mysite.
Leaves me no choice but to setup magento with base URL set to http://example.com/magento/ and it runs perfectly.
However the client wants me to feel hell and asks me to hide magento in the URL.
I’m not really versed in .htaccess and I know only simple rewrite codes so I tried forwarding any HTTP requests that start with /magento to the magento folder and came up with:
RewriteCond %{REQUEST_URI} !^/magento(.*)
RewriteRule (.*) /magento/$1 [L]
Just when I thought it was working, mysite links all became unaccessible and forwards to the magento system displaying it's 404 page.
So, uhm, can I ask for help how to construct the .htaccess to hide the /magento/ on the URLs without affecting the current system aka mysite?
Because you have existing applications off the webroot, you cannot get away with using nothing instead:
### webroot/.htaccess
RewriteRule ^whatiwanttouseinsteadofmagento/(.*)$ magento/$1 [L]
From how I see the problem you will not be able to hide magento completely and use your site as well in the same time.
If you want Magento in the root of the public folder you should just point the virtualHost to your magento installation but this will let your blog and your main controller out of the public view. This is more or less the same with what you did by redirecting all calls in the .htaccess to magento folder.
What I suggest is to change the magento name to something more anonymous like "shopping" or "cart", and remember that a folder rename is preferable to a .htaccess file in terms of security and performance.
Let's look at it:
RewriteCond %{REQUEST_URI} !^/magento(.*)
So we're saying the condition is anything that is not /magento(.*), so everything but that directory? This would redirect everything, including your blog, assets, and any other directories.
Without specifying each and every file that needs to be redirected to the magento directory, there really is no easy way of doing it. I suppose you could redirect any file that does not contain a "/" in it and ends with the extension .php to the magento directory. That way only files in the root web directory will redirect to magento, but if you used other directories inside the magento directory you'd still need to add separate rules for them.
this answer comes very late but I guess you wanted something like
RewriteCond %{REQUEST_URI} !^/(blog|assets|magento)(.*)$
RewriteRule ^(.*)$ /magento$1 [L]

How can I clean up Symfony admin routes?

My backend URLs look like this:
mysite.com/backend.php/blog
I'd like to change it to:
mysite.com/backend/blog
Technically this isn't limited to admin apps, as Symfony grants every application two front controller scripts. But I hate having the script name in URLs and as such I'd like to change it. Is this possible?
Thanks in advance.
Edit
#codecowboy - I did resolve this by creating a 'backend' directory in the web directory. I then copied over the .htaccess file symfony puts in web, and I moved the backend.php and backend_dev.php front controllers to /backend and renamed them index.php and index_dev.php. Then within each front controller I tell PHP to look one directory further up for the project config class. I've been doing this for a while now and it serves my needs perfectly. I actually wrapped this all up in a task so that setting up a new admin app is a 1 step processs.
You can add
#I'm no regular expression expert or mod_rewrite expert, this line probably has some bugs
RewriteRule ^backend(.*)$ backend.php [QSA,L]
to your .htaccess file right before
RewriteRule ^(.*)$ index.php [QSA,L]
and that solves 1/2 of your problem. Anything sent to yoursite.com/backend/xxx will be routed through backend.php. The other problem you get is with internal symfony routing. It will interpret yoursite.com/backend/xxx as a request for module "backend" and action "xxx". I'm sure it's not too hard to solve. Good Luck!

Categories