.htaccess 仅为客户端从url中删除index.php

.htaccess 仅为客户端从url中删除index.php,.htaccess,redirect,.htaccess,Redirect,我知道有些问题是这样的,但解决方法对我没有帮助。 如果没有定义请求文件(上面的代码),我将使用htaccess重定向到index.php。 我想添加一个代码行,如果用户请求,例如: 他将转向 但它将重定向到index.php。 有没有一种方法可以扩展我的代码,让它像我希望的那样工作 # Add Slash RewriteCond %{REQUEST_URI} !(/$|\.) RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] # Re

我知道有些问题是这样的,但解决方法对我没有帮助。 如果没有定义请求文件(上面的代码),我将使用htaccess重定向到index.php。 我想添加一个代码行,如果用户请求,例如: 他将转向 但它将重定向到index.php。 有没有一种方法可以扩展我的代码,让它像我希望的那样工作

   # Add Slash
    RewriteCond %{REQUEST_URI} !(/$|\.) 
    RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

# Redirect to index.php if the following sites were not match
RewriteBase /
RewriteCond %{REQUEST_URI} \.(php|sql|tgz|gz|txt|ttf|TTF|log|txt|ini|html|xml|xhtml|htm)$
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^/phpinfo.php$
RewriteCond %{REQUEST_URI} !^/out.php$
RewriteCond %{REQUEST_URI} !^/sitemap[^0-9]*\.xml$
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
完整代码:

DirectoryIndex index.php index.html

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

# Take off index.php
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} \.(php|sql|tgz|gz|txt|ttf|TTF|log|txt|ini|html|xml|xhtml|htm)$
RewriteCond %{REQUEST_URI} !^/((index|phpinfo|out)\.php|robots\.txt|sitemap[^0-9]*\.xml)$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?dir=$1 [QSA,L]

# Add Slash for non-files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

非常感谢。我想如果你把代码单独放在htaccess中,上面没有我的代码,它就会工作。我重定向到index.php时会遇到问题:如果您将代码放在我的代码之上,然后进行测试,您就会明白我的意思。(在下一条评论中进一步说明)问题是,到目前为止,所有指向index.php的重定向都将使用隐藏参数?dir=[URI]执行。客户端将看不到此参数,但index.php可以使用它。因此,在我将您的代码粘贴到我的上方后,这个隐藏参数将可见。我不知道为什么,但现在如果我想访问一个不存在的目录(通过mod_rewrite重定向到index.php),例如test/它将重定向到index.php?dir=test/但这不应该出现。不应为客户端显示参数?dir谢谢您的回复。好的,第一个问题解决了,但第二个问题出现了。创建一个目录,例如css,并在其中放置一个css文件。之后,尝试在浏览器中打开css文件:domain.com/css/file.css->您将得到一个未找到的错误。如果你愿意,我已经用你发布的代码做了一个现场演示。你可以告诉我,我会给你发送服务器的登录数据。是的,我收到了,我现在有一个电话,会调查一个小时。我登录了你的服务器,但它用德语显示了所有内容,我猜不出文件管理器会在哪里。我想了解您的目录结构,并尝试对.htaccess进行一些调整