小编Shi*_*aze的帖子

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

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

我将我的代码分成文件夹.索引位于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)

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

php .htaccess

5
推荐指数
1
解决办法
79
查看次数

Ubuntu 16.04 无法启用 .htaccess

我正在本地开发一个网站,刚刚从 Windows 切换到 Ubuntu 16.04 - 遗憾的是我的 .htaccess 似乎不起作用,因为重写规则不适用并且找不到源。

我激活了:

sudo a2enmod rewrite  
Run Code Online (Sandbox Code Playgroud)

rewrite_rule(共享)通过以下方式列出:

sudo apache2ctl -M
Run Code Online (Sandbox Code Playgroud)

我的网站文件(包括我的 .htaccess)位于

/var/www/html
Run Code Online (Sandbox Code Playgroud)

我的.htaccess

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# Hide Index
IndexIgnore *

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

# Remove 'php' folder in URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/$ php/$1.php [L] 

# Hide .php file ending in URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php …
Run Code Online (Sandbox Code Playgroud)

apache ubuntu .htaccess mod-rewrite

1
推荐指数
1
解决办法
1729
查看次数

标签 统计

.htaccess ×2

apache ×1

mod-rewrite ×1

php ×1

ubuntu ×1