我使用htacess删除php扩展并且它工作但我也有一个名为profile的页面,我缩短但是使页面名称被视为个人资料用户名,有没有办法解决这个问题?
我想要的结果是这样的:
localhost/path_folder/index.php
至localhost/path_folder/index
和
localhost/path_folder/profile?username=name
至localhost/path_folder/name
和删除扩展程序的htaccess
代码为:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC]
,个人资料页面的代码为:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /path_folder/profile.php?username=$1
答案 0 :(得分:1)
将此代码放入DOCUMENT_ROOT/.htaccess
文件中:
RewriteEngine On
## First try To internally redirect /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ /path_folder/$1.php [L]
## if PHP file not found then load profile page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /path_folder/profile.php?username=$1 [L,QSA]
答案 1 :(得分:0)
如果要删除文件扩展名
RewriteEngine On RewriteRule ^path_folder/([^/]*)$ path_folder/$1.php [L]
缩短userprofiles的网址
RewriteEngine On RewriteRule ^path_folder/profile/([^/]*)$ path_folder/profile?username=$1 [L]