Redirect index.php request to http://localhost/website/ using .htaccess

半世苍凉 提交于 2020-01-03 04:59:06

问题


I'm not so familiar with configuring my .htaccess yet so please help me out.

I have a link that goes to the index.php but I don't want index.php to appear in my url

eg. 
http://localhost/website/index.php

I want it to be redirected to the root folder which is

http://localhost/website/ 

So i tried searching for answers and this is what I got so far.

RewriteEngine on

Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://localhost/website/$1 [R=301,L]

Now when I try to click home in my local website, instead of redirecting me to

http://localhost/website

it is being redirected to this -

http://localhost/Applications/XAMPP/xamppfiles/htdocs/website/localhost/website/

Can anyone explain what's going on?


回答1:


did you try this one

RewriteRule ^(.*)$ /index.php/$1 [L] 



回答2:


The changes I made with my .htaccess does not take effect as soon as I refresh the page. Took me some time to clear my cache to see the effect. I tried different approaches to my question:

Options +FollowSymLinks
RewriteEngine on

#RewriteCond %{THE_REQUEST} ^.*/index.php
#RewriteRule ^(.*)index.php$ http://localhost/website/$1 [R=301,L]

#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /?(.*)/index\.php
#RewriteRule ^ /%1 [L,R=301]

#RewriteRule ^(.*)$ /index.php/$1 [L] 

The lines with # didn't solve my problem maybe its because of cache not being cleared, but anyways this line below solved my problem but took me 5 times to clear my cache before I actually saw the result.

RewriteRule ^index.php(.*)$ http://localhost/website/$1 [R=301,NC]

I got it from htaccess generator



来源:https://stackoverflow.com/questions/15778687/redirect-index-php-request-to-http-localhost-website-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!