我正在为我的网络应用程序使用 CodeIgniter,我想避免在视图中的所有 url 中继续使用 base_url() 函数。
现在这段代码就是我想要的:
<a href="/user/create">Click me to create user</a>
代替
<a href="<?php echo base_url(); ?>user/create">Click me to create user</a>
但是,指定“/user/create”会将我重定向到下面的 url,这是不正确的
http://localhost/user/create
我想要的是 href 中的“/user/create” url 应该自动将我重定向到
http://localhost/myapp/user/create
没有指定 base_url()
这可能吗?
这是我当前的 .htaccess 文件
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /myapp/
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
任何帮助将不胜感激。
谢谢