Remove index.php from url by htaccess

前端 未结 4 1227
时光取名叫无心
时光取名叫无心 2020-12-22 12:31

Im developing a php frame work and I am new to .htaccess rules. So I need to redirect url using .htaccess. Url is

http://localhost/rinocabs/index.php?/Galar         


        
相关标签:
4条回答
  • 2020-12-22 12:36

    When in doubt, go the Codeigniter route!

    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    Basically there is no reason to include what's going to be the domain portion of your url in the rewrite rule and condition, and your condition is looking funky. Looking at the codeigniter example above, all we need to do in our expression is: find the index.php segment in the path, and get rid of it, and rewrite to include it. Your expression assumes the path will always be the same...if that makes sense.

    0 讨论(0)
  • 2020-12-22 12:37
    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?$1 [L,QSA]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
    RewriteRule ^ %1 [R=301,L]
    

    use this

    localhost/rinocabs/index.php/Galary/Image/

    instead of

    localhost/rinocabs/index.php?/Galary/Image/

    0 讨论(0)
  • 2020-12-22 12:38

    Please try the following code. It's working properly.

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L]
    
    0 讨论(0)
  • 2020-12-22 12:56

    Please try below code :

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    
    0 讨论(0)
提交回复
热议问题