简体   繁体   English

使用.htaccess重写URL?

[英]url rewriting using .htaccess?

I am using codeigniter. 我正在使用codeigniter。 There is a url patern: localhost/mysite/application/assets/projects/projectname 有一个网址模式: localhost/mysite/application/assets/projects/projectname

The projectname part is dynamic. projectname部分是动态的。 Now I want to rewrite that url to: localhost/mysite/projectname 现在,我想将该网址重写为: localhost/mysite/projectname

Is it possible using .htaccess ? 是否可以使用.htaccess If it is what will be the code. 如果是的话,代码是什么。

Try this .htaccess 试试这个.htaccess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond $1 !^(index\.php|indexcp\.php?|resources|robots\.txt)
RewriteRule ^([A-Za-z0-9_/.-]+)$ index.php?$1 

RewriteRule ^(CSI) index.php?/CSI
AddType text/x-component .htc

EDIT 编辑

Once try this way 一旦尝试这种方式

RewriteRule ^(/application/assets/projects)$ http://localhost/mysite/$1 [R,NC,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM