如何通过htaccess在URL中添加index.php

Joh*_*rad 5 php .htaccess mod-rewrite url-rewriting

实际上我需要通过 htaccess 文件在我的应用程序 URL 中添加 index.php 。

我的网址是这样的。

http://localhost:8080/myapp/xyz/abs.html
Run Code Online (Sandbox Code Playgroud)

我需要将其更改为。

http://localhost:8080/myapp/index.php/xyz/abs.html
Run Code Online (Sandbox Code Playgroud)

谁能告诉我需要在 htaccess 文件中写入什么内容。

任何帮助将不胜感激。

谢谢。

anu*_*ava 5

有这个规则/myapp/.htaccess

RewriteEngine On
RewriteBase /myapp/

# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+) index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)


Doc*_*oot 1

大概需要内部重写,而不是外部重定向?在这种情况下,请尝试如下操作,在根 .htaccess 文件中使用 mod_rewrite:

RewriteEngine On
RewriteCond %{REQUEST_URI} !/index\.php/
RewriteRule ^myapp/(.*) /myapp/index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)

RewriteCond需要该指令来防止重写循环。(仅当尚未包含“/index.php/”时才重写。)