0

I want to rewrite assets directory from mysite.com/demo/assets/ to mysite.com/assets using htaccess.

i tried lots of combination but none of them works, i think it has something to do with my current htaccess parameters

Original code

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
AddDefaultCharset utf-8

I did the trick via bellow code, but js functions which are adding css parameters doesn't work any more.

  RedirectMatch 301 ^/demo/assets/(.*)$ /assets/$1

I have created actual /demo/assets folder and added htaccess files with bellow parameter, it also does the trick for css but js is still not working

RewriteEngine on
RewriteBase /demo/assets/
RewriteRule ^(.*)$ /assets/$1 [L,NC]

anybody help

Ok finally after full night research i found the source of issue. js is glitching because of tinymce library, when i upload it manually in demo/assets/plugins all seems to work fine!
now i am trying to find out why tinymce is glitching and keep it in shared /assets folder.

hope i can receive advice's.

strangely issue seems to be in demo/assets/plugins/tinymce/langs dir which contains only readme.md

Back Office
  • 71
  • 1
  • 13

2 Answers2

0

In your .htaccess file:

Redirect /demo/assets /assets
Javier C.
  • 7,859
  • 5
  • 41
  • 53
FAEWZX
  • 991
  • 7
  • 10
0

Using .htaccess

Try this :

RewriteEngine On
RewriteRule ^demo/assets/$ /assets/ [L,R=301]

OR

RedirectMatch uses a regular expression that is matched against the URL path.

RedirectMatch 301 ^/demo/assets/$ /assets/

Using routes.php file (in application/config/routes.php)

Try this :

$route['assets'] = "demo/assets/$1";

Then you have to change every link in your coding from <?php echo site_url();?>demo/assets/ to <?php echo site_url();?>assets/

Note :- This will be good solution for custom URLs in Codeigniter. NO NEED TO CHANGE .htaccess.

Please refer the CI documentation regarding URI routing for more information.

https://codeigniter.com/user_guide/general/routing.html

G_real
  • 1,137
  • 1
  • 18
  • 28
  • yes, i have multi directory setup where demo folder just contains index.php and config/custom-config.php files. i want to do redirect via htaccess because assets is called via base_url('assets/'); in multiple files and because of frequent devoper updates i do not feel comfortable modifying core script files. p.s. tried your htaccess it doesn't work – Back Office Feb 13 '19 at 19:00
  • @BackOffice `routes.php` is a config file, not a core file! – Vickel Feb 13 '19 at 19:21
  • I think, It's better to change `routes.php` file for this particular single redirect. – G_real Feb 13 '19 at 19:23
  • In core i was referring to base_url('assets/'); , will routs bypass base_url parameter ? reference to htaccess i tried new methods but page is still loading without css – Back Office Feb 13 '19 at 19:25
  • @BackOffice. Yes. It will bypass base_url parameter. All routes ONLY from `/demo/assets/` will be redirected to `/assets/`. At least try it that way. – G_real Feb 13 '19 at 19:29
  • After changing to this, `$route['assets'] = "demo/assets/$1";` you have to change every link in your coding from `demo/assets/` to `assets/` – G_real Feb 13 '19 at 21:10
  • well as mentioned above there is no site_url();?>demo/assets/ it is executed from base_url('assets/'); and i do not want to touch view folder. – Back Office Feb 13 '19 at 22:30