PHP & .htaccess - 在 URL 中隐藏文件夹
PHP & .htaccess - Hide folder in URL
我制作了一个网络应用程序,并将所有页面 (.php) 留在项目文件夹的根目录中。我现在想将每个页面从项目根文件夹移动到 /view 文件夹中。
原始URL示例:project/about-us
原文件:project/about-us.php
期望URL:project/about-us
原始文件位置:project/views/about-us.php
我已经尝试了 Hiding folder in URL using .htaccess 但到目前为止还没有成功。
我的 .htaccess 已经有以下规则来处理文件扩展名和缓存。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php [NC,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ .html [NC,L]
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
如有任何建议,我们将不胜感激。
更新:文件结构
如果您想要特定的 url 加载特定的文件:
RewriteRule ^about-us(|/)$ views/about-us.php [L]
我制作了一个网络应用程序,并将所有页面 (.php) 留在项目文件夹的根目录中。我现在想将每个页面从项目根文件夹移动到 /view 文件夹中。
原始URL示例:project/about-us
原文件:project/about-us.php
期望URL:project/about-us
原始文件位置:project/views/about-us.php
我已经尝试了 Hiding folder in URL using .htaccess 但到目前为止还没有成功。
我的 .htaccess 已经有以下规则来处理文件扩展名和缓存。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ .php [NC,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ .html [NC,L]
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
如有任何建议,我们将不胜感激。
更新:文件结构
如果您想要特定的 url 加载特定的文件:
RewriteRule ^about-us(|/)$ views/about-us.php [L]