问题
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