1

I'm trying to redirect url's in my /joomla/ folder containing "rsform" to the same url but except for /joomla/ /formulieren/. However my tried .htaccess rewrite doesn't work. I tried:

RewriteEngine on
RewriteCond %{REQUEST_URI} rsform
RewriteRule  ^(.+)$ http://watervriendengeleen.nl/joomla/ [L,R=301]

And other URL related rewrites like Redirect /joomla/index.php?option=com_rsform&formId=12&Itemid=99999 http://sitename.com/formulieren/index.php?option=com_rsform&formId=12&Itemid=99999 which didn't work either.

Any thoughts?

  • what is the name of your .htaccess file? also have you enabled mod_rewrite in apache (sudo a2enmod rewrite). – Frank Aug 14 '14 at 21:01
  • @Frank simply .htaccess (in the root, joomla itself also has .htaccess-files in /joomla/ and /formulieren/), yes. – Raimond van Mouche Aug 14 '14 at 21:03
  • @Frank additionally I'm using RewriteEngine on RewriteCond %{REQUEST_URI} !rsform RewriteCond %{REQUEST_URI} !template RewriteCond %{REQUEST_URI} !image RewriteCond %{REQUEST_URI} !administrator RewriteRule ^(.+)$ http://sitename.com/joomla/ [L,R=301] in the formulieren folder's .htaccess and that works fine – Raimond van Mouche Aug 14 '14 at 21:04
  • Do any rewrite rules work? If not then your web server might not have URL Rewrite rules enabled thus ignoring .htaccess files. Can you let us know what web server you are on? Are you on linux or windows? – Frank Aug 14 '14 at 21:06
  • @Frank they do, however I just noticed that redirects on the /joomla/ folder get ignored. I'm using a CentOS6.0 Linux web server with Apache 2.2.27 - maybe Joomla is the blocking factor... – Raimond van Mouche Aug 14 '14 at 21:10
1

You can't match against the query string (everything after the ?) in the regex patter of a RewriteRule or a Redirect. You need to use mod_rewrite's %{QUERY_STRING} variable:

RewriteEngine On
RewriteCond %{QUERY_STRING} rsform
RewriteRule  ^(.+)$ http://watervriendengeleen.nl/formulieren/? [L,R=301]
locked by Community Sep 23 '14 at 8:01
  • Ah, allright. Unfortunately, your proposed code has the same result as mine, it gets ignored. :( – Raimond van Mouche Aug 14 '14 at 22:17
  • @RaimondvanMouche you sure your htaccess file is being read? Do you have all of the necessary modules loaded and options set to be able to use htaccess files and mod_rewrite? – Jon Lin Aug 14 '14 at 22:24
  • how can I check the first? on the latter, yes, for example in the formulieren directory I have a .htaccess with RewriteEngine on RewriteCond %{REQUEST_URI} !rsform RewriteCond %{REQUEST_URI} !template RewriteCond %{REQUEST_URI} !image RewriteCond %{REQUEST_URI} !administrator RewriteRule ^(.+)$ http://watervriendengeleen.nl/joomla/ [L,R=301] and that works perfectly fine. It's really weird. – Raimond van Mouche Aug 14 '14 at 22:27
  • @RaimondvanMouche if you have rewrite rules in subdirectories and you try to access the subdirectory, any mod_rewrite rules in parent directories are completely ignored – Jon Lin Aug 14 '14 at 22:29
  • Ah that's good to know. Unfortunatly, I tried your suggested rewrites in both the root .htaccess and the /joomla/'s .htaccess to no avail... – Raimond van Mouche Aug 14 '14 at 22:32
1

I think the following mod_rewrite directives should do what you require, however, whether they do anything at all may be dependent on your configuration.

RewriteEngine on
RewriteCond %{QUERY_STRING} rsform
RewriteRule ^joomla/(.+)$ http://watervriendengeleen.nl/formulieren/$1 [L,R=301]

This redirects all requests for files in your /joomla/ subfolder, containing the string "rsform" anywhere in the query string (as suggested by your example) to the same URL in the /formulieren/ subfolder. The query string is also copied across to the substituted URL.

However, I do wonder whether you should be redirecting here, as it may be more preferable to internally rewrite the request if possible? ie. remove the R=301 flag. (But this may or may not work for you?)

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.