I would like to redirect registration page to homepage by using .htaccess now my code is redirecting to /component/users/?view=login&Itemid=437 which is login page. I would like to make registration and front-end login page not accessible for users.

So the target is to redirect /component/users/?view=login&Itemid=437 and /index.php?option=com_users&view=registration&Itemid=999 to "403 error page"

# RewriteBase /

# Disable calls to user registration ("register", this url ends with: view=registration))
# Send all blocked request to homepage, use Flag [F] for 403 Forbidden error!
RewriteCond %{QUERY_STRING} (view=registration) [NC]
RewriteRule .* index.php [F]

## Begin - Joomla! core SEF Section.
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
## End - Joomla! core SEF Section.
  • I understand that you would like to do that with .htaccess, but may I ask why you do not want to do it within Joomla itself with making these pages available only for already registered users, or custom groups, or for admins only?
    – Zollie
    Feb 23, 2019 at 17:07
  • @Zollie have done it already but users can access www.mypage.com/component/users/?view=login&Itemid=437 but public users can access it anyway by inputting this link to their web browser.
    – 10101
    Feb 23, 2019 at 17:10
  • You can try any Joomla site. Some are locked somehow but some are still accessible. For example http://www.moghees.co.uk/index.php?option=com_users&view=registration&Itemid=999 or http://noblebrand.pl/index.php?option=com_users&view=registration&Itemid=999
    – 10101
    Feb 23, 2019 at 17:28
  • Yes, I understand you now. I’ll check this a bit more.
    – Zollie
    Feb 23, 2019 at 18:00
  • @Zollie so basically by adding /index.php?option=com_users&view=registration&Itemid=999to domain you will be on registration page or it will redirect to login page. But some websites like https://www.linux.com/ or https://www.guggenheim.org/ restricted access. So it drops an error or redirecting to another page.
    – 10101
    Feb 23, 2019 at 18:06

1 Answer 1


If you really want to close out visitors from users pages, then maybe you can also create a system plugin and onAfterroute event you could use something like the following code:

public function onAfterRoute()
    if ($this->app->getRouter()->getVar('option') === 'com_users')
        $guestRedirectUrl = '/index.php';
        $this->app->redirect($guestRedirectUrl, $status = 303);

(if you use it on a live webserver, the leading slash is not needed in the redirect url).

Or another version, as @Sharky has suggested, the following is more effective on sef urls:

if ($this->app->input->get('view') === 'registration')
    // let's redirect...

This is just a sudden idea on this, instead of using .htaccess for redirect. From the router you can get Itemid or view too, so it can work on more precise condition too like:

if ($this->app->getRouter()->getVar('view') === 'registration') and on many other versions of conditions. if sef urls are used this will not work on those pages, however this will:

$pagevars = $this->app->getRouter()->getVars();
if ($pagevars['option'] === 'com_users' && $pagevars['Itemid'] === '437')
    // do redirect...

(Itemid should be changed to your registration page's Itemid of course).

(Itemid and option (component name) is available via router too even if someone uses sef urls).

Sidenote: creating a plugin for these kind of small tasks sounds quite stupid, but it is not if you can/would later use this same custom system plugin of yours to do few other things on your site via a system plugin. It comes handy at those times too.

  • Better to use Input for operations like this. $this->app->getRouter()->getVar('view') returns NULL on URLs like /component/users/login. Also remove leading slash before index.php, it causes redirect to root directory even if Joomla is installed in a subfolder.
    – Sharky
    Feb 23, 2019 at 22:03
  • @Sharky - thanks for the comments! It could work with using input too, maybe even better, I have not really compared. The leading slash is only if someone is trying these on localhost, where without slash it does not work. However I would update the answer with these short but important notes.
    – Zollie
    Feb 24, 2019 at 5:01
  • Please do test your code. $this->app->getRouter()->getVar('Itemid') returns NULL on /component/users/login?Itemid=437. I tried this on localhost (XAMPP) and leading slash was not needed but having it caused the redirect to root directory.
    – Sharky
    Feb 24, 2019 at 9:06
  • @Sharky - my code is tested, my friend. The particular Itemid is just an example in the code and that itemid is just what the OP's own Itemid (437) if you read his question above. Your Itemid of your login page (given by your router) is different as usually for everybody else. The code has to be customized with your own given Itemid(given by the router not by you) as I noticed in my answer. I tested the code on my localhost and I get the results what I wrote. I use WAMP server on localhost and it does not work without leading slash on my local host (but it depends on server settings too).
    – Zollie
    Feb 24, 2019 at 9:17
  • @Sharky - my registration page Itemid is 1138 for example...
    – Zollie
    Feb 24, 2019 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.