通过.htaccess从URL剪切文件夹路径

Shi*_*aze 5 php .htaccess

我试图缩短我的网址,但遗憾的是找不到任何有用的东西.

我将我的代码分成文件夹.索引位于root,就像我的.htaccess一样.这些文件夹的名称就像文件扩展名一样,所以php,js,css [...]

我有如下链接:

localhost/php/getBets.php
Run Code Online (Sandbox Code Playgroud)

并希望它是

localhost/getBets/
Run Code Online (Sandbox Code Playgroud)

我已经有了最后剪切.php扩展名的部分,所以这是我的完整.htacces

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# Hide Index
IndexIgnore *

# Forbid accessing certain sites
RedirectMatch 403 ^/.gitignore$
RedirectMatch 403 ^/.htaccess$
RewriteRule ^(?!index)(?!.*getBets).*\.(php|rb|py|txt|md|sql|inc)$ - [F,L,NC]

# Hide .php file ending in URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我如何实现这一目标吗?:) 非常感谢!

Abh*_*jar 2

对于您所需的网址,您可以在根目录中使用以下规则进行重写,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/$ php/$1.php [L]
Run Code Online (Sandbox Code Playgroud)