resolving index.php issue at url laravel htaccess - .htaccess

I know this question is asked alot and there are alot of answers on "how to resolve index.php issue in laravel".
However, I tried multiple ways in order to solve it from .htaccess on live dedicated server with WebsitePanel in order to remove index.php from URL. I tried a couple of ways however let me describe the issue here, index.php not only have changed the url, but also some of the css and javascript stuff are not loaded as well while most of them are loaded, CSS seems pretty fine but fonts are also changed.
It was working well at a shared host but here in a dedicated host it has alot of problems.
Is there a .htaccess code to solve this issue? and does index.php affects on CSS and is it normal?
my current htaccess is as follow:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /index.php [L]
</IfModule>

You don't need to modify index.php or .htaccess. If you did this, revert to original files.
To remove index.php or public from URLs, you need to setup virtual host for Laravel project (there are instructions both for nginx and apache).
After that restart web server.

This is the most common problem in Laravel. When you upload your code to a webserver, your page will be in
www.web-something.com/index.php
So there are 2 things you should do,
1.Change the .htaccess file and also
2.Change the Virtual Host Settings in your server. Link :for setting up a virtual host in apache
After this you will be able to visit the directory just fine. Also about the CSS , problem , Its probably because of the virtual host settings. Itll get fixed up once you point everything to the right directory.

For IIS Windows Server, the .htaccess needs to be translated to web.config and this works like a charm.
here is the link:
How to enable modrewrite on IIS Web Server
In case Someone needed this in future!

Related

Remote site not working on local server

So I'm setting up a local environment for testing and development. We use CodeIgniter as our framework.
But when I copy the whole server to the local server (I have XAMPP), and navigate to the root, all I see is a directory structure - it doesn't display anything at all that I would expect to see from the website.
I spent 4+ hours (over several days) trying every .htaccess and httpd.conf suggestion I could find on Google, stackoverflow, these forums, and more. I am able to get a 500 server error when adding garbage to the .htaccess file, so I know it's being processed. But I think my problem is possibly unrelated to the .htaccess file settings. (I don't really care if index.php shows up on the URL bar locally.)
There is no index.php on our server's root (again, our site is built with CodeIgniter). Nor anywhere else in the site's directory structure, (except /application/views/user/template/original). When I access the site live, in the URL bar it pulls up the domain name followed by: "/user/login". Looking into the /application/views/user folder shows a login_view.php, but when I try to access it directly, I get an Access Forbidden 403 error.
Per this solution, I also tried changing the DocumentRoot (in C:\xampp\apache\conf\http.conf) from "C:/xampp/htdocs" to "C:/xampp/htdocs/othersites/mysite" Same result.
How is the site loading remotely, but not locally?
Check your base_url in config.php
Here is working .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myproject
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
It turns out, for some reason, the site's root index.php wasn't in the git repo that I cloned from. I have that now, along with another (different) .htaccess file.
After changing the base_url in application\config\config.php to my localhost variant, it's working!
If I ever figure out why they didn't have index.php in that repo, I'll let you all know...

having headache wtih codeigniter mod_rewrite ~!

I read lots of the mod_rewrite for codeigniter and lots of them were talking about creating a .htaccess file and inside the file with something like
I'm a beginner with codeigniter so I'm learning from youtube tutorials.
at first I only have apache 2.2 installed to run my php and after using codeigniter with mod_rewrite I realize it's easier to install wamp so I uninstalled apache, mysql then installed wamp which has everything.
After that I continued with the tutorial on youtube about mod_write. I activated the module in wamp.
Created this .htaccess file inside ci_intro which is the root folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I went to the config/config.php and changed
$config['index_page'] = '';
things didn't work. I was getting the 404error then I was trying out few things in
RewriteBase /ci_intro/
and also even deleted the whole project and because I backed things up right before I try the mod_write. Even after I retrieved the backup. I still didn't get the error404 page.
I just keep on getting..
Since I'm using wamp, when I go to my localhost there's a section saying my project which is ci_intro...I click on it the image above comes out.
I put my mouse over to check what's the link showing when mouse over and the link shows
[CODE]http://localhost/ci_intro[CODE]
anyone know what's going on here?
That browser page you are getting, is a result of using a fake or unregistered domain-name... The browser is unable to resolve it to an IP address, so it "helps" you by reinterpreting your request as a search term.
This is happening because you are using "www.domain.tld" instead of "localhost" to access your website.
I'm not sure which WAMP distrubution you are using (there are many "WAMPs"), but your options are:
A) Edit the Windows Hosts file (C:\Windows\system32\drivers\etc\hosts) to locally resolve "www.domain.tld" to the local IP addres 127.0.0.1 (and make sure your VirtualHost or Server has that domain name as part of it's ServerName directive).
B) Use "localhost" instead... http://localhost/
C) Use a WAMP that automatically sets up website VirtualHosts for you and has a LocalDNS feature like Wamp-Developer Pro does - so none of the above matters.
Now once you get passed that, there might be some other issues... I'm guessing that .htaccess file should be in the DocumentRoot folder itself.

.htaccess URL Rewrite Failing - The requested URL was not found on this server

I have a very simple rewrite rule. My entire .htaccess file is as follows:
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ /index.php?page=$1 [L,NC]
This works perfectly on one of my development machines running Apache. It does not work however on my other development machine running Apache (mod_rewrite listed in PHP info under apache2handler). Nor does it work on the live server, which I think is running Windows.
I have tried adding the following:
RewriteBase /
I'm no mod_rewrite wizard and I'm sure it's a very simple solution but it is eluding me currently and keep receiving a 404 not found error.
One thing that is different on the two environments in which this doesn't work, is that the site is not in the root of the URL. So for example it is http://localhost/site and www.example.com/site
I have tried various syntax adjustments in the .htaccess file, and also adding the site to the base:
RewriteBase /site
Remove the 'RewriteBase /site' and try removing the / before index.php
The slash should't be there with use of .htaccess
RewriteEngine On
ReWriteRule ^([a-zA-Z0-9\-]+)$ index.php?page=$1 [L,NC]

redirecting all traffic to my home page using .htaccess

Can someone help me on how to configure my .htaccess? I have read lots of tutorials on how to redirect all traffic to one single page but it didn't helped me.
My problem is, I have a wordpress site before and I decided to remove all my files and uninstall everything under wordpress. In short, I put up a fresh public_html on my server.
I have permanent links given to my clients before like http://domain.com/web/pricing/ or http://domain.com/web-login/uploads/image.jpg. Some of the links contains lots of sub folders like ..domain.com/web/me/you/anyone/none.
I am using this .htaccess code
ErrorDocument 404 /notfound.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I only have two pages on my server right now; index.php and notfound.php. The above code works only if Im trying to visit these kind of url ..domain.com/web and ..domain.com/web.php and nothing else.
If I put try to visit ..domain.com/web/me/you/anyone/none or even a short link that has a slash at the end like ..domain.com/web.php/ it gives me the notfound.php but with lots of errors. CSS and javascripts are not loaded. Only the texts.
Add this to the header of your 2 pages:
<base href="/">
The additional paths that are added to the URI is probably making the relative links use the incorrect URI base. So if you had:
<img src="image/foo.jpg">
And it works fine when you request domain.com/web.php because the URI base is /, but if you request domain.com/web/me/you/anyone/none, the URI base is then /web/me/you/anyone/ and the browser is going to think that the image is at /web/me/you/anyone/image/foo.jpg.

CakePHP and .htaccess in shared hosting environment

Greetings!
I have CakePHP based app on shared hosting I wonder if there's a way to clean up the url through .htaccess. What bugs me is that I have to have index.php in it or I get a 404:
project.com/index.php/controller/method
Initially I was getting a 404 error no matter what and my host admin ended up setting RewriteEngine off and this is what it looks like now
<IfModule mod_rewrite.c>
RewriteEngine off
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Is there fix for this without the .htaccess? As it is right now, does it pose any type of security risk?
Thanks
You need three .htaccess files :
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
If the one you pasted in your question is the one at the root of your website, that's probably where your problem comes from. These directives file would rewrite URLs to project.com/webroot/, which doesn't exist. It should redirect to project.com/app/webroot/, which will in turn rewrite to index.php?url=$1 (relative to project.com/app/webroot/).
I'm not pasting the files here; the three of them are available in the CakePHP releases as well as in the Book: http://book.cakephp.org/2.0/en/installation/url-rewriting.html (check the 3rd item in the page).
Are you sure the mod_rewrite module is enabled on your shared hosting?

Resources