如何使用.htaccess在编码器中缩短url


how to shorten url in codeigniter using .htaccess?

我的项目url是:

localhost/foldername/main(classname)/showmenu(methodname)/different_slugs // (e.g home,aboutus etc)

如何将此url缩短为:

localhost/foldername/different_slugs //(e.g home,aboutus etc)

您可以使用代码编写器的路由。如欲了解更多有关路由的资讯,请按此。

您必须使用.htaccess

RewriteRule ^foldername/main/showmenu/(.*?)/$ localhost/foldername/$1

更多信息可以在这里找到

您可以使用CodeIgniter的路由器来实现这一点。只需打开application/config文件夹中的routes.php文件,并添加以下行:

$route['(:any)'] = 'main/showmenu';

这将重定向任何(和所有)到指定地址。

对于您的.htaccess,您只需要:

RewriteEngine on
RewriteBase /foldername/ # in case you're working in a folder
RewriteCond %{REQUEST_URI} !'.(gif|jpe?g|png|css|js) [NC] # don't process files with these extensions - will be served normally
RewriteRule ^(.*)$ index.php/$1 [L] # redirect everything else to index