简体   繁体   English

使用mod_rewrite完全删除index.php

[英]Using mod_rewrite to remove index.php completely


I'm looking for a way to remove any file name that is index.php from the URL. 我正在寻找一种方法来从URL中删除任何为index.php的文件名。 The main reason I want to try and do this is because I have directories with "index.php" in them. 我想尝试执行此操作的主要原因是因为我的目录中包含“ index.php”。 So instead of getting... 所以没有得到...
http://localhost/members/index/ http:// localhost / members / index /
I am hoping to achieve something more like... 我希望能实现更多...
http://localhost/members/ http:// localhost / members /

The code below is currently what I have in my .htaccess file. 下面的代码当前是我的.htaccess文件中的代码。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]


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

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]

I really appreciate the help and any suggestions! 我非常感谢您的帮助和任何建议! Thank you so much and God bless! 非常感谢,上帝保佑!

If all you want to do is 'remove' index.php from your URLs then you just need to ensure Apache knows that index.php can be used as a directory index. 如果您要做的只是从URL中“删除” index.php,则只需确保Apache知道index.php可用作目录索引。

DirectoryIndex index.php

You can put that in your Apache config, VirtualHost or .htaccess file. 您可以将其放在您的Apache配置,VirtualHost或.htaccess文件中。

Just use this: 只需使用此:

RewriteCond %{THE_REQUEST} ^.*index.php.*

That's it ;) 而已 ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM