htaccess only one file in subfolder and keeping the url

Viewed 63

I need to put files in a new folder like this: domain.com/newsite/newpanel/events.php

There are other files in the server like:

  • domain.com/events.php,
  • domain.com/oldsite/events.php etc.

Requirement 1: I cannot redirect everything (because old implementations exist) with generic rules, so I only want to redirect specific urls. domain.com/events should now skip the old files and go to domain.com/newsite/newpanel/events.php

Requirement 2: I tried something like this

RewriteRule ^events /newsite/newpanel/events/$1 [P]

but the url on the url bar will change. Is it possible for it to display domain.com/events?

thank you all!

1 Answers

EDIT: Since OP has mentioned different URLs in comments section so adding solution as per that here.

RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/CProjects/events/?$ [NC]
RewriteRule ^(.*)$ CProjects/folderA/folderB/events [L]


Based on your shown samples, could you please try following. Please make sure you clear your browser cache before testing your URLs after putting these Rules into your .htaccess file.

RewriteEngine ON
RewriteCond ^/events/?$ [NC]
RewriteRule ^(.*)$ newsite/newpanel/events.php [L]
Related