Lab 8.2 - RewriteRule not working
I followed step-by-step (I'm on a Fedora machine) the provided solution, and after enabling the log for Rewrite Rules, it DOES seem to work, even if I'm not sure about that last message (' to get passed through to next API URI-to-filename handler'):
[Sat Jan 12 14:13:16.457004 2019] [rewrite:trace2] [pid 957:tid 140718237189888] mod_rewrite.c(482): [client ::1:46332] ::1 - - [localhost/sid#55d059c0fd20][rid#7ffb78008c00/initial] init rewrite engine with requested uri /foo/bar [Sat Jan 12 14:13:16.457064 2019] [rewrite:trace3] [pid 957:tid 140718237189888] mod_rewrite.c(482): [client ::1:46332] ::1 - - [localhost/sid#55d059c0fd20][rid#7ffb78008c00/initial] applying pattern '^/foo/(.*)' to uri '/foo/bar' [Sat Jan 12 14:13:16.457085 2019] [rewrite:trace2] [pid 957:tid 140718237189888] mod_rewrite.c(482): [client ::1:46332] ::1 - - [localhost/sid#55d059c0fd20][rid#7ffb78008c00/initial] rewrite '/foo/bar' -> '/scripts/foo.cgi?bar' [Sat Jan 12 14:13:16.457098 2019] [rewrite:trace3] [pid 957:tid 140718237189888] mod_rewrite.c(482): [client ::1:46332] ::1 - - [localhost/sid#55d059c0fd20][rid#7ffb78008c00/initial] split uri=/scripts/foo.cgi?bar -> uri=/scripts/foo.cgi, args=bar [Sat Jan 12 14:13:16.457110 2019] [rewrite:trace2] [pid 957:tid 140718237189888] mod_rewrite.c(482): [client ::1:46332] ::1 - - [localhost/sid#55d059c0fd20][rid#7ffb78008c00/initial] forcing '/scripts/foo.cgi' to get passed through to next API URI-to-filename handler
Alas, when I visit http://localhost/foo/bar, the address is still the same (I also tried with wget/curl, so it doesn't seem a browser issue)
Comments
-
Hi Carlo ! Did the last step in exercise 8.1 work?
It was :
Restart Apache and test your new script. http://localhost/scripts/foo.cgi?bar
If the exercise 8.1 functions then it is a rewrite issue if it did not then the foo.cgi script needs attention.0 -
Yes, it did work. There was only a misconception on my part, sorry!
The redirection was supposed to be "transparent" and that's exactly what's happening. I see the URL http://localhost/foo/bar instead of the URL http://localhost/scripts/foo.cgi?bar
I missed the "transparent" part and for some reason I was convinced I should have been seeing the URL change to http://localhost/scripts/foo.cgi?bar.
Sorry and thanks for your time.
0 -
Hi,
I use CentOS
Lab 8.1 is Ok. It works.
Lab 8.2 is not working. --> The requested URL /scripts/foo/bar was not found on this server.I've done the virtualhost lab from the previous chapter. Probably the root of the reason is the file namevhost.conf.
I don't understand how the file namevhost.conf must be corrected. How can I find _default_namevhost section ?Regards,
Alexey0 -
Hi Alexey,
There are sample configuration files in the SOLUTIONS directories that should help. In the SOLUTIONS/s_07 directory is a file "namevhost.conf " with the "default " server stanza included.
Let me know if this helps.
Lee0 -
Hi. I am also having issues with this lab.
(Ubuntu 18)
After following the instructions, all I get is the, "Not Found. The requested URL was not found on this server." message when trying to access http://localhost/foo/barIt's not particularly clear where the default stanza is in the namevhost.conf file. (I tried putting them most places in the file..)
Also, on an Ubuntu system does one create the /etc/apache2/sites-enabled/rewrite.conf file as well as adding the rewrite commands to the 000-default.conf file? I think I've tried most variations, with no success.0 -
I have now tried this in ubuntu20 and it also fails at 8.2.
Anyone have any ideas? I thought it was maybe to do with the actual RewriteRule given.
for rewrite.conf it's given as,RewriteRule \ˆ/foo/(.*) /scripts/foo.cgi?$1 [L,PT]
But where it's to be added to the 000-default.conf file it's given as,RewriteRule ˆ/foo/(.*) /scripts/foo.cgi?$1 [L,PT]
There's a backslash that I think is superfluous in the first instance.Then I looked again at http://httpd.apache.org/docs/current/rewrite/intro.html and all their examples have double quotes around each section,
RewriteRule "ˆ/foo/(.*)" "/scripts/foo.cgi?$1" [L,PT]
Having been through pretty much every permutation of these with no success, I await insight from a greater mind!!
Please, this is incredibly frustrating!
0 -
I re-tested lab 8.2. It worked on Ubuntu 20.04 as described. Lets see if we can get yours going.
Quotes vs backslash, either will work, it is just coding style.
The three lines to be added to the 000-default.conf file (Debian and buddies) must be INSIDE the last "VirtualHost" stanza.
My file looks like:
root@ubuntu:/etc/apache2/sites-enabled# tail 000-default.confRewriteEngine on
RewriteOptions inherit
RewriteRule ^/foo/(.*) /scripts/foo.cgi?$1 [L,PT]
VirtualHostVerify apache can see the cgi directoy, here is my test using lynx :
student@ubuntu:~/LFT$ lynx -dump http://localhost/scripts/foo.cgi?bar
Content-type: text/plain
File is bar
Verify the rewrite works:
student@ubuntu:~/LFT$ lynx -dump http://localhost/foo/bar
Content-type: text/plain
File is bar
_
I hope this helps. LeeNOTE: the formatting of the stanza is messed up in this editor, screen shot included.
0 -
Hi Lee.
Unfortunately this hasn't fixed the problem.Here's a screenshot of what I have, including the contents of rewrite.conf, namevhost.conf and testing of namevhost.
Thoughts?
0 -
Well that is interesting.
The three re-write directives should be in 000-default.conf or rewrite.conf, not both. On Ubuntu I have less issues if I modify 000-default.conf. What you have there looks fine, the first lynx command shows the cgi is working so it is just the rewrite. The re-write needs only two additional things, the configuration directives which look fine and the rewrite apache2 module.Can you please check your enabled modules against mine? See below :
0 -
Let's trace the rewrite and see if it is trying at all.
- In /etc/apache2/apache.conf locate "LogLevel" directive.
- Change LogLevel to "LogLevel alert rewrite:trace4"
- restart apache2
- test url with lynx
- use grep to show the rewrite messages "grep rewrite /var/log/apache2/error.log "
Below is a working example for you to use as a comparison.
0 -
Hi Lee.
So I removed any mention of Rewrite from the namevhost.conf file.
I removed the rewrite.conf file entirely.
I added the cgid.conf and cgid.load mods to my mods-enabled directory and removed the cgi.load mod that was there (as per the lab instructions). My mods directory now looks like this,Only the 000-default.conf file has any mention of the rewrite rules.
It still didn't work.
Here's a snippet from the error.log,
It's definitely not the same as yours. For some reason the IP addresses look like they're IPv6...
But more interesting is in how the "applying pattern..." step is definitely wrong.instead of,
applying pattern '^/foo/(.*)
I have,applying pattern '\xcb\x86/foo/(.*)'
hmmm, that rings a bell...
So instead of selecting the text in the browser and middle-buttoning it into vim (to reduce the chance of typos), I typed it in and it worked.
On the lab, ˆ is used instead of ^.
Thanks for your time on this Lee, the rewrite:trace was invaluable.
I think it needs to be clearer in the lab that rewrite.conf doesn't work in Ubuntu and shouldn't be added.
0
Categories
- All Categories
- 207 LFX Mentorship
- 207 LFX Mentorship: Linux Kernel
- 734 Linux Foundation IT Professional Programs
- 339 Cloud Engineer IT Professional Program
- 166 Advanced Cloud Engineer IT Professional Program
- 66 DevOps Engineer IT Professional Program
- 132 Cloud Native Developer IT Professional Program
- 122 Express Training Courses
- 122 Express Courses - Discussion Forum
- 6K Training Courses
- 40 LFC110 Class Forum - Discontinued
- 66 LFC131 Class Forum
- 39 LFD102 Class Forum
- 222 LFD103 Class Forum
- 17 LFD110 Class Forum
- 34 LFD121 Class Forum
- 17 LFD133 Class Forum
- 6 LFD134 Class Forum
- 17 LFD137 Class Forum
- 70 LFD201 Class Forum
- 3 LFD210 Class Forum
- 2 LFD210-CN Class Forum
- 2 LFD213 Class Forum - Discontinued
- 128 LFD232 Class Forum - Discontinued
- 1 LFD233 Class Forum
- 3 LFD237 Class Forum
- 23 LFD254 Class Forum
- 689 LFD259 Class Forum
- 110 LFD272 Class Forum
- 3 LFD272-JP クラス フォーラム
- 10 LFD273 Class Forum
- 113 LFS101 Class Forum
- LFS111 Class Forum
- 2 LFS112 Class Forum
- 1 LFS116 Class Forum
- 3 LFS118 Class Forum
- 3 LFS142 Class Forum
- 3 LFS144 Class Forum
- 3 LFS145 Class Forum
- 1 LFS146 Class Forum
- 2 LFS147 Class Forum
- 8 LFS151 Class Forum
- 1 LFS157 Class Forum
- 18 LFS158 Class Forum
- 5 LFS162 Class Forum
- 1 LFS166 Class Forum
- 3 LFS167 Class Forum
- 1 LFS170 Class Forum
- 1 LFS171 Class Forum
- 2 LFS178 Class Forum
- 2 LFS180 Class Forum
- 1 LFS182 Class Forum
- 4 LFS183 Class Forum
- 30 LFS200 Class Forum
- 737 LFS201 Class Forum - Discontinued
- 2 LFS201-JP クラス フォーラム
- 17 LFS203 Class Forum
- 118 LFS207 Class Forum
- 1 LFS207-DE-Klassenforum
- LFS207-JP クラス フォーラム
- 301 LFS211 Class Forum
- 55 LFS216 Class Forum
- 50 LFS241 Class Forum
- 44 LFS242 Class Forum
- 37 LFS243 Class Forum
- 13 LFS244 Class Forum
- 1 LFS245 Class Forum
- 45 LFS250 Class Forum
- 1 LFS250-JP クラス フォーラム
- LFS251 Class Forum
- 146 LFS253 Class Forum
- LFS254 Class Forum
- LFS255 Class Forum
- 6 LFS256 Class Forum
- LFS257 Class Forum
- 1.2K LFS258 Class Forum
- 9 LFS258-JP クラス フォーラム
- 116 LFS260 Class Forum
- 156 LFS261 Class Forum
- 41 LFS262 Class Forum
- 82 LFS263 Class Forum - Discontinued
- 15 LFS264 Class Forum - Discontinued
- 11 LFS266 Class Forum - Discontinued
- 23 LFS267 Class Forum
- 18 LFS268 Class Forum
- 29 LFS269 Class Forum
- 200 LFS272 Class Forum
- 1 LFS272-JP クラス フォーラム
- LFS274 Class Forum
- 3 LFS281 Class Forum
- 8 LFW111 Class Forum
- 257 LFW211 Class Forum
- 180 LFW212 Class Forum
- 12 SKF100 Class Forum
- SKF200 Class Forum
- SKF201 Class Forum
- 791 Hardware
- 199 Drivers
- 68 I/O Devices
- 37 Monitors
- 98 Multimedia
- 174 Networking
- 91 Printers & Scanners
- 85 Storage
- 754 Linux Distributions
- 82 Debian
- 67 Fedora
- 16 Linux Mint
- 13 Mageia
- 23 openSUSE
- 147 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 351 Ubuntu
- 465 Linux System Administration
- 39 Cloud Computing
- 71 Command Line/Scripting
- Github systems admin projects
- 91 Linux Security
- 78 Network Management
- 101 System Management
- 47 Web Management
- 56 Mobile Computing
- 17 Android
- 28 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 366 Off Topic
- 114 Introductions
- 171 Small Talk
- 20 Study Material
- 534 Programming and Development
- 293 Kernel Development
- 223 Software Development
- 1.2K Software
- 212 Applications
- 182 Command Line
- 3 Compiling/Installing
- 405 Games
- 312 Installation
- 79 All In Program
- 79 All In Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)