Htaccess redirect deleting index.php

I want the user to be able to use $_SERVER['PATH_INFO']

as a placeholder for which the file should serve and get rid of the index.php in the address bar

For example, I want to serve me.com/index.php/settings1

like me.com/settings1

etc. for any PATH_INFO that the user navigates to.

How can I write this normally htaccess? I don't even know where to start

If that helps, I accept hosting from hosting.

Based on @EddyFreddy's suggestion, I've tried both of the ways mentioned in this question with no luck. This is how the file looks so far:

suPHP_ConfigPath /home/user/php.ini
    <Files php.ini>
        order allow,deny    
        deny from all   
    </Files>

RewriteEngine On
RewriteBase /   

RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
RewriteRule .? http://mysite.com%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L] # tried with and without the `?`

      

+3


source to share


2 answers


This can be handled easily by mod_rewrite. Use this code in .htaccess in DOCUMENT_ROOT:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# external redirect from /index.php/foo to /foo/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php(/[^\s\?]+)? [NC]
RewriteRule ^ %1/ [L,R]

# external redirect to add trailing slash
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+((?!.+/[\s\?])[^\s\?]+) [NC]
RewriteRule ^ %1/ [L,R]

# internal forward from /foo to /index.php/foo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php%{REQUEST_URI} [L,NC]

      



Once you are sure everything is working fine, change R

to R=301

.

+8


source


After long term evaluation, I found out that the version from anubhava does not work for me in all cases. So I tried this modified version. It will handle existing files in existing rulers correctly and will not create double slashes.



Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

###### Add trailing slash (optional) ######
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ $1/ [R=301,L]

###### external redirect from /index.php/foo to /foo ######
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php(/.+)?[\s\?] [NC]
RewriteRule ^ %1 [L,R=301]

###### internal forward from /foo to /index.php/foo ######
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php%{REQUEST_URI} [L]

      

+1


source







All Articles