简体   繁体   中英

Remove Main Folder Name from URL in Codeigniter via htacess

I installed the Codeigniter in the folder and site is running from the folder.

Installation folder is 2019

For example: domainame/2019/

Detail Page url is: domainname/2019/content/postname

But i want the URL structure like just need hide the name of folder of the URL

post should be open after that

Detail page url is: domainname/content/postname

it should not effect main folder

Please give me any solution for that

You could use URLREWRITE, or Mod_Rewrite, to do this (Assuming you use URL Parameters).

Eg using pattern ^([^/]+)/([^/]+)/?$ with subsistution URL 2019/index.php?{R:1}={R:2} would convert domainname/2019/index.php?content=postname to domainname/content/postname

See https://httpd.apache.org/docs/2.4/rewrite/remapping.html for more details on how to do this on Linux/Apache via .htaccess

RewriteEngine on
RewriteBase /domainame/2019

RewriteRule ^$ /domainame/2019/index\.php [L]
RewriteCond $1 !^(index\.php|assets|repository|favicon\.gif)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond $1 !^(images.*.(bmp|jpg|jpeg|gif|png|doc|docx|xls|xlsx|ppt|pptx|pdf|rtf|txt|zip|rar|odt))
RewriteCond $1 !^(images.*.(BMP|JPG|JPEG|GIF|PNG|DOC|DOCX|XLS|XLSX|PPT|PPTX|PDF|RTF|TXT|ZIP|RAR|ODT))

RewriteCond $1 !^(images.*.(WEBM|AAC|M4A|F4A|MP3|OGG|OGA|OGV|FLV|MP4|M4V|F4V|MOV))
RewriteCond $1 !^(images.*.(webm|aac|m4a|f4a|mp3|ogg|oga|ogv|flv|mp4|m4v|f4v|mov))

RewriteRule ^(.*)$ /domainame/2019/index.php?/$1 [L]

Assume domainame is a folder

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