Simple. Just don't ever have "index.php" in any of your code or links. It doesn't matter if they can still access it if they manually enter index.php in the address bar. If you don't have any actual links that use it, google won't catalog it so you won't get penalized for having duplicate content.
Remove index.php in Laravel 5
I begin enter my site in adress: localhost/laravel -> after click contact menu and my url is: localhost/laravel/contact -> It is a url normal But If I enter my site in address: localhost/laravel/index.php -> after click contact menu and my url is: localhost/laravel/index.php/contact How to remove index.php from url? I use url() for my site, example: url('contact');
I think it is. Google will index url have index.php because it is another url. I will have duplicate content. I can't let anyone enter my site is localhost/laravel/index.php and run anything in my site with url have index.php. Thanks for reply, Cronix.
Google will index url have index.php
Only if you have a link containing it, like <a href="yoursite.com/index.php/something"> If all of your links are <a href="yoursite.com/something"> then google won't know about "index.php" and so it won't crawl it or index it.
If all of your links are clean and don't have "index.php" physically in them, it's not like google is going to start making urls up and see if they work. Like if all of your links are yoursite.com/something, it's not like google's going to say "Hmm, I wonder if it works if we insert index.php in there".
The key is to never have index.php in the links on your site. Search engines will only crawl the links that are in your html.
What I'm meaning is you are saying if you go to the address bar and physically type and add index.php to it, yes you'll get the content, but search engines will never add extra stuff to urls that aren't present in the links on the site.
I use function url() to general url. Example: url('contact') -> It will general is "localhost/laravel/contact" but if in url have index.php so then url('contact') will is "localhost/laravel/index.php/contact", All my links in website these are have index.php. If google will not index mysite. Ok, Thanks Cronix, But I still want know more that How to remove index.php in my site.
I run a site that gets millions of unique visitors/month. It literally has tens of thousands of links in it (it's a massive national real estate site). I've never gotten urls crawled by search engines that weren't physically present in my html, or duplicate content. They only crawl what they can see, and they only see what's in your HTML.
but if in url have index.php so then url('contact') will is "localhost/laravel/index.php/contact"
url() uses the APP_URL value from .env to generate the urls, so if you don't have 'index.php' in there, like 'http://yoursite.com/index.php' then it will never generate urls with index.php in them when you use the helpers. It should just be 'http://yoursite.com' and then url('contact') will always generate 'http://yoursite.com/contact'
Thanks Cronix! So then we have no way to remove index.php, including .htaccess ?
Thanks Cronix again! I have search it in forum and I see:
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) / [R=301,NE,L]
It work for my site ( tipskailler.com ) But it dont work for localhost: localhost/laravel/public_html/index.php So... How to edit it to it work for localhost. Add "public_html" where in .htaccess
It would be best to set up a virtualhost in apache, so you can access it with http://yourapp.test instead of http://localhost/laravel, then you can use the same code no matter what server you upload it to. Just create a new vhost and set document root to /your/path/to/laravel/public.
You shouldn't have to fumble with the htaccess file it works as is.
You might need to add
RewriteBase /yoursite/
after RewriteEngine On
You need to set up folder structure correctly, which has been covered before.
It's different @jlrdw. He also wants it so that if a user manually adds index.php to the url in the address bar, it redirects without index.php. Not sure why it matters as it's never been an issue on any of the sites I've worked on.
OP why would they bother typing index.php? All would, should still work. I have never seen that be an issue. Perhaps some over worry.
In fact if a link is hit bringing up another page, the index.php just goes away anyway.
Cronix, thanks for reply. It have been work for me. I used .htaccess above. I have problem when I change http to https, I lost all index from google what google index for http version. You can enter: site:tipskailler.com and see version http, all them redirect to https://tipskailler.com/index.php And with above code , I can redirect index.php to none index.php I know that index.php will general the urls. I just want hidden it.
I checked the site:tipskailler.com search, and all of the links I clicked on redirected to https://tipskailler.com, which is wrong. All http urls redirect to your homepage. That's really bad. They should just redirect to the same url, except use https instead of http. This is a big problem.
For instance: http://www.tipskailler.com/danh-muc/ngon-ngu-lap-trinh-website.html
redirects to https://tipskailler.com/
instead of https://www.tipskailler.com/danh-muc/ngon-ngu-lap-trinh-website.html
something like
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://tipskailler/$1 [L,R=301]
Thanks Cronix so much! You did see my problem. I just have some urls what index from google of version http Let imagine! If my site is big, It will is a big problem. I will learn about .httacess. thanks again.
If you put those 2 lines I wrote above in your .htaccess it should work.
It basically just says "if the url accessed is via port 80 (non-https), then redirect to the same url, except using https"
I think you were confusing the term "index" (as in search engines index your site) and index.php, the php file.
Was curious
https://laracasts.com/index.php/discuss
Jeffrey wasn't worried about it with Laura cast
Neither does Facebook
https://www.facebook.com/index.php // works
Taylor on laravel site also
https://laravel.com/index.php // works
https://laravel.com/index.php/docs/5.7 // works
Please or to participate in this conversation.