Hi all,
I've already asked this question on a number of apache forums and have received no response. I hoped someone here could help me understand why this rewriterule doesn't work:
RewriteRule ^/index.php?option=login$ /register [R=301,L]
This is on a joomla-3.9 system running on fedora29. It fails with "COMPONENT NOT FOUND", as if it thinks the option=login is a joomla component that it's trying to run. Of course I don't want it to interpret the URI, but instead just redirect.
I've tried adding this to the .htaccess in the document root, as well as the apache config for the domain. I have other redirects in that config that I believe are working properly.
I've also tried using redirects:
Redirect 301 /index.php?option=login https://linuxsecurity.com/register
Here is the rewrite output during a request:
[Fri Mar 01 11:31:58.144013 2019] [rewrite:trace1] [pid 27899:tid 139741257266944] mod_rewrite.c(482): [client 192.168.1.7:47112] 192.168.1.7 - - [linuxsecurity.com/sid#55fa6d60df40][rid#7f17e40218d0/initial] pass through /index.php [Fri Mar 01 11:31:58.144874 2019] [rewrite:trace1] [pid 27899:tid 139741257266944] mod_rewrite.c(482): [client 192.168.1.7:47112] 192.168.1.7 - - [linuxsecurity.com/sid#55fa6d60df40][rid#7f17e40218d0/initial] [perdir /var/www/www.linuxsecurity.com-443/html/] pass through /var/www/www.linuxsecurity.com-443/html/index.php 192.168.1.7 - - [01/Mar/2019:11:31:58 -0500] "GET /index.php?option=login HTTP/1.1" 404 2748 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.42 Safari/537.36" 0/56728 855/9853/2748 linuxsecurity.com [Fri Mar 01 11:31:58.329012 2019] [rewrite:trace1] [pid 27899:tid 139740946867968] mod_rewrite.c(482): [client 192.168.1.7:47112] 192.168.1.7 - - [linuxsecurity.com/sid#55fa6d60df40][rid#7f17e400df90/initial] pass through /index.php, referer: https://linuxsecurity.com/index.php [Fri Mar 01 11:31:58.330180 2019] [rewrite:trace1] [pid 27899:tid 139740946867968] mod_rewrite.c(482): [client 192.168.1.7:47112] 192.168.1.7 - - [linuxsecurity.com/sid#55fa6d60df40][rid#7f17e400df90/initial] [perdir /var/www/www.linuxsecurity.com-443/html/] pass through /var/www/www.linuxsecurity.com-443/html/index.php, referer: https://linuxsecurity.com/index.php [Fri Mar 01 11:31:58.363485 2019] [rewrite:trace1] [pid 27899:tid 139741475346176] mod_rewrite.c(482): [client 192.168.1.7:47116] 192.168.1.7 - - [linuxsecurity.com/sid#55fa6d60df40][rid#7f17c8032c90/initial] pass through /templates/shaperhelix_child/fonts/fontawesome-webfont.woff2, referer: https://linuxsecurity.com/templates/shaperhelix_child/css/font-awesome.min.c... [Fri Mar 01 11:31:58.364415 2019] [rewrite:trace1] [pid 27899:tid 139741475346176] mod_rewrite.c(482): [client 192.168.1.7:47116] 192.168.1.7 - - [linuxsecurity.com/sid#55fa6d60df40][rid#7f17c8032c90/initial] [perdir /var/www/www.linuxsecurity.com-443/html/] pass through /var/www/www.linuxsecurity.com-443/html/templates/shaperhelix_child/fonts/fontawesome-webfont.woff2, referer: https://linuxsecurity.com/templates/shaperhelix_child/css/font-awesome.min.c... 192.168.1.7 - - [01/Mar/2019:11:31:58 -0500] "GET /templates/shaperhelix_child/fonts/fontawesome-webfont.woff2?v=4.7.0 HTTP/1.1" 304 - "https://linuxsecurity.com/templates/shaperhelix_child/css/font-awesome.min.c..." "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.42 Safari/537.36" 0/1983 932/438/0 linuxsecurity.com 192.168.1.7 - - [01/Mar/2019:11:31:58 -0500] "GET /index.php HTTP/1.1" 200 19631 "https://linuxsecurity.com/index.php" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.42 Safari/537.36" 2/2045372 457/20542/19631 linuxsecurity.com
What more can I do to troubleshoot this?
Hi,
Alex wrote:
I've already asked this question on a number of apache forums and have received no response. I hoped someone here could help me understand why this rewriterule doesn't work:
RewriteRule ^/index.php\?option=login$ /register [R=301,L]
I think you may be caught by RewriteRule not matching against query strings. Per the docs:
What is matched? ... * If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.
Source: https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#what_is_matched
I believe you want to use something like:
RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^/index.php?$ /register [R=301,L]
It's been a while since I've done this, so I'm not sure whether the "?" after index.php is matched. You may need to adjust that pattern.
On 01Mar2019 12:51, todd zullinger tmz@pobox.com wrote:
Alex wrote:
I've already asked this question on a number of apache forums and have received no response. I hoped someone here could help me understand why this rewriterule doesn't work:
RewriteRule ^/index.php\?option=login$ /register [R=301,L]
I think you may be caught by RewriteRule not matching against query strings. Per the docs:
What is matched? ... * If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.
Source: https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#what_is_matched
I believe you want to use something like:
RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^/index.php?$ /register [R=301,L]
It's been a while since I've done this, so I'm not sure whether the "?" after index.php is matched. You may need to adjust that pattern.
I would expect to not want the "?" in the RewriteRule; it should be stripped by the process which breaking things into the path and the query_string. Untested opinion, it has been a while for me too.
And in principle you want to escape the ".": "."
Cheers, Cameron Simpson cs@cskk.id.au
Hi,
RewriteRule ^/index.php\?option=login$ /register [R=301,L]
I think you may be caught by RewriteRule not matching against query strings. Per the docs:
What is matched? ... * If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.
Source: https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#what_is_matched
I believe you want to use something like:
RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^/index.php?$ /register [R=301,L]
It's been a while since I've done this, so I'm not sure whether the "?" after index.php is matched. You may need to adjust that pattern.
I would expect to not want the "?" in the RewriteRule; it should be stripped by the process which breaking things into the path and the query_string. Untested opinion, it has been a while for me too.
And in principle you want to escape the ".": "."
Both with the ? and without didn't make a difference. It didn't work either way.
It seemed to ignore it entirely. It continued to report "component not found", as if it's trying to process the option= portion.
If no one has any further ideas, perhaps you know of a better resource?
Of course I'm also happy to try other ideas...
Hi,
Alex wrote:
I believe you want to use something like:
RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^/index.php?$ /register [R=301,L]
It's been a while since I've done this, so I'm not sure whether the "?" after index.php is matched. You may need to adjust that pattern.
I would expect to not want the "?" in the RewriteRule; it should be stripped by the process which breaking things into the path and the query_string. Untested opinion, it has been a while for me too.
Yep. I saw some suggestions with the trailing '?' so I included it in the example, since I wasn't sure either way. It's not wanted or needed, now that I've tested.
And in principle you want to escape the ".": "."
No doubt. I tend to try and make any regexp's tightly defined when I'm putting them into use. Though making them a bit loose to start can help to ensure that the rest of the rule is hit.
Both with the ? and without didn't make a difference. It didn't work either way.
It seemed to ignore it entirely. It continued to report "component not found", as if it's trying to process the option= portion.
If no one has any further ideas, perhaps you know of a better resource?
Of course I'm also happy to try other ideas...
I just tested locally. Here's what worked for me:
[tmz@f29 ~]$ cat /etc/httpd/conf.d/rewrite_test.conf <Directory /var/www/html> RewriteEngine on RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^index.php /register [R=301,L,QSD] </Directory>
[tmz@f29 ~]$ curl -I 'localhost/index.php?option=login' HTTP/1.1 301 Moved Permanently Date: Sat, 02 Mar 2019 03:00:52 GMT Server: Apache/2.4.38 (Fedora) Location: http://localhost/register Content-Type: text/html; charset=iso-8859-1
The URI was matched without a leading /. To strip the query string, the QSD flag is handy. That's in httpd >= 2.4.0.
Hi,
RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^/index.php?$ /register [R=301,L]
It's been a while since I've done this, so I'm not sure whether the "?" after index.php is matched. You may need to adjust that pattern.
I would expect to not want the "?" in the RewriteRule; it should be stripped by the process which breaking things into the path and the query_string. Untested opinion, it has been a while for me too.
Yep. I saw some suggestions with the trailing '?' so I included it in the example, since I wasn't sure either way. It's not wanted or needed, now that I've tested.
And in principle you want to escape the ".": "."
No doubt. I tend to try and make any regexp's tightly defined when I'm putting them into use. Though making them a bit loose to start can help to ensure that the rest of the rule is hit.
Both with the ? and without didn't make a difference. It didn't work either way.
It seemed to ignore it entirely. It continued to report "component not found", as if it's trying to process the option= portion.
If no one has any further ideas, perhaps you know of a better resource?
Of course I'm also happy to try other ideas...
I just tested locally. Here's what worked for me:
[tmz@f29 ~]$ cat /etc/httpd/conf.d/rewrite_test.conf <Directory /var/www/html> RewriteEngine on RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^index.php /register [R=301,L,QSD] </Directory> [tmz@f29 ~]$ curl -I 'localhost/index.php?option=login' HTTP/1.1 301 Moved Permanently Date: Sat, 02 Mar 2019 03:00:52 GMT Server: Apache/2.4.38 (Fedora) Location: http://localhost/register Content-Type: text/html; charset=iso-8859-1
The URI was matched without a leading /. To strip the query string, the QSD flag is handy. That's in httpd >= 2.4.0.
This didn't work. That is exactly what I now have in my config for the virtual domain. It still appears that it's not matching.
Does anyone have any further ideas about what could be causing it to bypass the rule?
Here's a failed request: 151.106.10.153 - - [03/Mar/2019:08:01:37 -0500] "GET /index.php?option=login HTTP/1.1" 404 2748 "http://www.linuxsecurity.com/index.php?option=login" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" 0/49047 836/9379/2748 linuxsecurity.com
I've pasted the trace1 output for a request here: https://pastebin.com/EighLUWw
Thanks, Alex
Hi,
I've also noticed the following in the .htaccess file in the document root as part of joomla:
# 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]
Could these somehow be overriding the config in the virtual domain config file?
On Sun, Mar 3, 2019 at 8:02 AM Alex mysqlstudent@gmail.com wrote:
Hi,
RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^/index.php?$ /register [R=301,L]
It's been a while since I've done this, so I'm not sure whether the "?" after index.php is matched. You may need to adjust that pattern.
I would expect to not want the "?" in the RewriteRule; it should be stripped by the process which breaking things into the path and the query_string. Untested opinion, it has been a while for me too.
Yep. I saw some suggestions with the trailing '?' so I included it in the example, since I wasn't sure either way. It's not wanted or needed, now that I've tested.
And in principle you want to escape the ".": "."
No doubt. I tend to try and make any regexp's tightly defined when I'm putting them into use. Though making them a bit loose to start can help to ensure that the rest of the rule is hit.
Both with the ? and without didn't make a difference. It didn't work either way.
It seemed to ignore it entirely. It continued to report "component not found", as if it's trying to process the option= portion.
If no one has any further ideas, perhaps you know of a better resource?
Of course I'm also happy to try other ideas...
I just tested locally. Here's what worked for me:
[tmz@f29 ~]$ cat /etc/httpd/conf.d/rewrite_test.conf <Directory /var/www/html> RewriteEngine on RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^index.php /register [R=301,L,QSD] </Directory> [tmz@f29 ~]$ curl -I 'localhost/index.php?option=login' HTTP/1.1 301 Moved Permanently Date: Sat, 02 Mar 2019 03:00:52 GMT Server: Apache/2.4.38 (Fedora) Location: http://localhost/register Content-Type: text/html; charset=iso-8859-1
The URI was matched without a leading /. To strip the query string, the QSD flag is handy. That's in httpd >= 2.4.0.
This didn't work. That is exactly what I now have in my config for the virtual domain. It still appears that it's not matching.
Does anyone have any further ideas about what could be causing it to bypass the rule?
Here's a failed request: 151.106.10.153 - - [03/Mar/2019:08:01:37 -0500] "GET /index.php?option=login HTTP/1.1" 404 2748 "http://www.linuxsecurity.com/index.php?option=login" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" 0/49047 836/9379/2748 linuxsecurity.com
I've pasted the trace1 output for a request here: https://pastebin.com/EighLUWw
Thanks, Alex
I turn this on when I'm debugging Rewrite rules: # Apache 2.4 - rewrite debug - trace0:trace8 RewriteLog /var/log/httpd/rewrite.log LogLevel rewrite:trace4
Bill
On 3/1/2019 10:08 PM, Todd Zullinger wrote:
Hi,
Alex wrote:
I believe you want to use something like:
RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^/index.php?$ /register [R=301,L]
It's been a while since I've done this, so I'm not sure whether the "?" after index.php is matched. You may need to adjust that pattern.
I would expect to not want the "?" in the RewriteRule; it should be stripped by the process which breaking things into the path and the query_string. Untested opinion, it has been a while for me too.
Yep. I saw some suggestions with the trailing '?' so I included it in the example, since I wasn't sure either way. It's not wanted or needed, now that I've tested.
And in principle you want to escape the ".": "."
No doubt. I tend to try and make any regexp's tightly defined when I'm putting them into use. Though making them a bit loose to start can help to ensure that the rest of the rule is hit.
Both with the ? and without didn't make a difference. It didn't work either way.
It seemed to ignore it entirely. It continued to report "component not found", as if it's trying to process the option= portion.
If no one has any further ideas, perhaps you know of a better resource?
Of course I'm also happy to try other ideas...
I just tested locally. Here's what worked for me:
[tmz@f29 ~]$ cat /etc/httpd/conf.d/rewrite_test.conf <Directory /var/www/html> RewriteEngine on RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^index.php /register [R=301,L,QSD] </Directory> [tmz@f29 ~]$ curl -I 'localhost/index.php?option=login' HTTP/1.1 301 Moved Permanently Date: Sat, 02 Mar 2019 03:00:52 GMT Server: Apache/2.4.38 (Fedora) Location: http://localhost/register Content-Type: text/html; charset=iso-8859-1
The URI was matched without a leading /. To strip the query string, the QSD flag is handy. That's in httpd >= 2.4.0.
users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org
Hi,
On Fri, Mar 8, 2019 at 1:57 PM Bill Shirley bshirley@memphis.apirx.biz wrote:
I turn this on when I'm debugging Rewrite rules: # Apache 2.4 - rewrite debug - trace0:trace8 RewriteLog /var/log/httpd/rewrite.log LogLevel rewrite:trace4
Thanks for that. I've been using rewrite:trace3, and even that is a lot of log data.
I was eventually able to figure this out. I used the following to redirect all the requests for the old linuxsecurity.com to the new one:
RewriteRule ^content/view/(.*)$ /index.php?option=com_content&view=article&id=$1 [L,R=301]
The register issue was solved with this rewrite:
# /index.php?option=login RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^index.php$ https://linuxsecurity.com/register [R=301,L,QSD]
Thanks, Alex
Bill
On 3/1/2019 10:08 PM, Todd Zullinger wrote:
Hi,
Alex wrote:
I believe you want to use something like:
RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^/index.php?$ /register [R=301,L]
It's been a while since I've done this, so I'm not sure whether the "?" after index.php is matched. You may need to adjust that pattern.
I would expect to not want the "?" in the RewriteRule; it should be stripped by the process which breaking things into the path and the query_string. Untested opinion, it has been a while for me too.
Yep. I saw some suggestions with the trailing '?' so I included it in the example, since I wasn't sure either way. It's not wanted or needed, now that I've tested.
And in principle you want to escape the ".": "."
No doubt. I tend to try and make any regexp's tightly defined when I'm putting them into use. Though making them a bit loose to start can help to ensure that the rest of the rule is hit.
Both with the ? and without didn't make a difference. It didn't work either way.
It seemed to ignore it entirely. It continued to report "component not found", as if it's trying to process the option= portion.
If no one has any further ideas, perhaps you know of a better resource?
Of course I'm also happy to try other ideas...
I just tested locally. Here's what worked for me:
[tmz@f29 ~]$ cat /etc/httpd/conf.d/rewrite_test.conf <Directory /var/www/html> RewriteEngine on RewriteCond %{QUERY_STRING} ^option=login$ RewriteRule ^index.php /register [R=301,L,QSD] </Directory> [tmz@f29 ~]$ curl -I 'localhost/index.php?option=login' HTTP/1.1 301 Moved Permanently Date: Sat, 02 Mar 2019 03:00:52 GMT Server: Apache/2.4.38 (Fedora) Location: http://localhost/register Content-Type: text/html; charset=iso-8859-1
The URI was matched without a leading /. To strip the query string, the QSD flag is handy. That's in httpd >= 2.4.0.
users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org
users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.org Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org