我正在尝试为网站项目创建干净/漂亮的URL,这样.php
扩展名将被隐藏,我将能够将URL转换为
example.com/user.php?profile=john-doe
到
example.com/user/john-doe
这是我能想到的代码:
RewriteEngine On
# Rewrite /foo/bar to /foo/bar.php
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]
# Return 404 if original request is /foo/bar.php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$" [NC]
RewriteRule .* - [L,R=404]
# NOTE! FOR APACHE ON WINDOWS: Add [NC] to RewriteCond like this:
# RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$" [NC]
#setting query for querying pages
RewriteRule ^(.*?)/(.*?)/?$ $1?name=$2 [NC]
但是我们不能正常工作,如果能得到此固定的或更完善的.htaccess
配置以实现我的目标,将不胜感激。
答案 0 :(得分:0)
尝试在route.php中
$route['default_controller'] = 'your main controller';
$route['your desire variable after project name'] = 'your controller/your function name which is used in code';
like,
$route['contact'] = 'MainCtrl/contact';
您只能使用“联系人”来调用控制器中可用的函数,因此您的链接将以较短的形式转换