.htaccess尝试在没有重定向404错误的情况下使用斜线


.htaccess trying to use slashes without redirect 404 error

使用mydomain.com/something 时,我正在努力防止404错误和重定向

它抛出404错误,因为页面something.php不存在。我希望它提交到索引页面,这样我就可以用php捕获值并在我的应用程序中使用它。我还想把它与删除扩展名(.php)结合起来,但仍然可以访问页面。例如,我希望能够键入mydomain.com/contact.php,但仍然能够使用mydomain.com/something,并在页面不存在的情况下将其提交到索引页面,而不是mydomain.com/contact.php。

希望有人能帮助我,因为我已经尝试了很多不同的事情,但似乎都不起作用。我能得到的最接近的是使用以下htaccess代码:

DirectoryIndex index.php
Options +FollowSymLinks
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index'.php|robots'.txt|css|index|js|robots'.txt|favicon'.ico)
RewriteRule ^(.*)$ index.php?/$1 [L]

然而,当文件不存在时,我只想将值作为斜杠提交到索引页,它似乎不起作用,挂起并最终抛出404。

DOCUMENT_ROOT/.htaccess文件中尝试此代码:

DirectoryIndex index.php
Options +FollowSymLinks
Options -MultiViews
RewriteEngine on
RewriteBase /
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
相关文章: