简体   繁体   中英

Remove folder name from URL in codeigniter

here is my URL like:

example.com/abc/xyz/controller/function

here in above URL abc and xyz are folder name.

how to remove "abc" and "xyz" from URL using .htaccess ?

here is my .htaccess :

 RewriteEngine On RewriteCond $1 !^(index\\\\.php|resources|robots\\\\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L,QSA] RewriteCond %{REQUEST_URI} ^/?[^/]+/[^/]+/([^/]+)/([^/]+)/?$ [NC] RewriteRule ^(.*)$ /%1/%2/? [NC,R,L] 

To remove the abc and xyz in example.com/abc/xyz/controller/function using .htaccess do this:

Options +FollowSymlinks
RewriteEngine on
AddDefaultCharset UTF-8

RewriteCond %{REQUEST_URI} ^/?abc/xyz/controller/function/?$ [NC]
RewriteRule ^(.*)$ /controller/function [NC,R,L]

The bottom two lines will remove the first two folders from links of the format example.com/letters/letters/letters/letters :

RewriteCond %{REQUEST_URI} ^/?[a-z]+/[a-z]+/([a-z]+)/([a-z]+)/?$ [NC]
RewriteRule ^(.*)$ /%1/%2/? [NC,R,L]

This accepts any characters for folder names and deletes the first two folders from the URL:

RewriteCond %{REQUEST_URI} ^/?[^/]+/[^/]+/([^/]+)/([^/]+)/?$ [NC]
RewriteRule ^(.*)$ /%1/%2/? [NC,R,L]

You can try this one:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /folderName/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.


    ErrorDocument 404 /index.php
</IfModule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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