2

I have a site and it works to type "www.mysite.com/folder/" (if i have a index file in that folder).

It also works to type "www.mysite.com/folder/index.php"

All fine and good, but I want it so if you type /index.php it will remove the index.php on the end also if I use a form and post to index.php I don't want that to show in the url.

I have looked around and seen every solution say .htaccess rewrite, but It don't seem to be working / or its just not the same thing that I want?

or do I need to use javascript and update the address bar?

(I'm using WAMP)

EDIT:

Things I've have tried:

1

httpd.conf

AllowOverride All

2

I have enabled: Apache modules> rewrite_module

3

I have created a .htaccess placed in my wamp/www folder

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 

4

wamp/apps/phpmyadmin/config.inc.php added

$cfg['index_page'] = '';

EDIT 2: This look like it works, but it messes up my POST to index.php so it breaks my login (It don't start the session).

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
Patrik Fröhler
  • 1,221
  • 1
  • 11
  • 38
  • for index.php, you don't need ANYTHING fancy. just `DirectoryIndex index.php`. If you want ALL php scripts to be seen as `/path/to/script` instead of `/path/to/script.php`, then you will need some mod_rewrite magic. – Marc B Jun 08 '16 at 16:51
  • What **possible effect** did you think that amending `wamp/apps/phpmyadmin/config.inc.php` would have on **anything** other than `phpMyAdmin` You do realise that phpMyAdmin is just a took that helps you fiddle with a `MYSQL` database _i hope_ – RiggsFolly Jun 08 '16 at 18:21
  • @RiggsFolly I didn't think I't but I just added it because I had seen it as a suggesting somewhere. – Patrik Fröhler Jun 08 '16 at 18:26
  • **Beware** There is lots of advice out there, most of it is written by morons, specially in the WAMPServer area – RiggsFolly Jun 08 '16 at 18:29
  • Or this one http://stackoverflow.com/questions/4365129/htaccess-remove-index-php-from-url – RiggsFolly Jun 08 '16 at 18:36
  • @RiggsFolly If the answer for the duplicate question does not resolve the OP's problem, is it really a duplicate question? I request re-opening (or perhaps helping the OP solve his problem). – cssyphus Jun 08 '16 at 20:53

1 Answers1

1

An .htaccess file is definitely the correct solution. If it isn't working, try one of these possible answer:

.htaccess not working on localhost with XAMPP

How to use .htaccess in WAMP Server?

.htaccess not working on WAMP


Update: Re-reading your question, you might be using an older htaccess script (for PHP < 5.2.6 version). I'm not sure if the script will work in current versions. Try:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

The ? after index.php in final line is the difference

If above doesn't help, what version of PHP does the PHP command phpinfo() report?

<?php
    phpinfo();
    die();
Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111
  • ok, good I at least know that its .htaccess thats the solution to my problem, but I have already looked at those solutions^ and tried the stuff but noting changes on the server still /index.php shows if i type it, (I have restarted wamp services) – Patrik Fröhler Jun 08 '16 at 17:27
  • That did not work either, and php info: PHP Version 5.5.12 – Patrik Fröhler Jun 08 '16 at 20:48
  • One more point - your problem is likely due to WAMP issue rather than htaccess issue. How important is it to you to resolve this in the WAMP environment? *If you are working in a WAMP dev environment now but will later upload to production environment (perhaps a shared hosting LAMP config) then you can rest assured that the `htaccess` code you posted above will work there.* – cssyphus Jun 08 '16 at 20:56
  • Yeah, I guess that's true it's not that important right now while using WAMP, just thought I't would be nice and easy. – Patrik Fröhler Jun 08 '16 at 20:59
  • Yeah, so did I. Sometimes those xampp/wamp environs have their peculiarities. I was hoping Rory would help out as he could probably put his finger right on the problem with a bit of head-scratching, but he's pretty busy. – cssyphus Jun 08 '16 at 21:04
  • If you can do it on Apache with a rewrite you can do it on a windows version of Apache – RiggsFolly Jun 08 '16 at 23:37
  • 1
    @PatrikFröhler Well, Rory confirms that it will definitely work, and he's an authority on WAMP / Apache / PHP. If it's worth the fuss, you can dig into it and I'm sure you'll resolve the matter. However, you won't have the problem when you move to your production server. *Best wishes with your project* – cssyphus Jun 09 '16 at 00:50
  • Thanks for the help, really appreciates it , I updated my post with something that I got to almost work, it does remove the index.php but when I use it I cant POST to index.php anymore. – Patrik Fröhler Jun 09 '16 at 12:06