Hosting Operations
Read-only, can be slowFind Web Server Redirect Rules
Browsers report a redirect loop or HTTP/HTTPS behavior disagrees, and you need to find redirect rules before changing DNS or TLS.
Command
grep -RInE 'return[[:space:]]+30[18]|rewrite[[:space:]]|Redirect[[:space:]]|RewriteRule|RewriteCond' fixtures/nginx fixtures/apache
Before you run this
System impact: Read-only. Can create load on large logs, directories, filesystems, or process tables.
When not to use it: Do not assume every rewrite causes a client-visible redirect. Inspect status codes, conditions, and the matching server block before editing.
Expected output
Config paths and redirect or rewrite lines, enough to identify which file needs careful review.
System impact
Read-only, can be slow. Nothing changes. The command searches config text for common redirect and rewrite directives.
Scope this to the smallest useful path or service on busy systems.
Recovery / rollback: no state is changed.
When to use it
Use when browsers report too many redirects, HTTP redirects to the wrong place, or HTTPS redirects back to HTTP.
When not to use it
Do not assume every rewrite causes a client-visible redirect. Inspect status codes, conditions, and the matching server block before editing.
Watch this command run
Command transcript
This sanitized transcript shows the commands and output shape without exposing host details.
$ grep -RInE 'return[[:space:]]+30[18]|rewrite[[:space:]]|Redirect[[:space:]]|RewriteRule|RewriteCond' sample-files/nginx sample-files/apache
sample-files/nginx/sites-enabled/example.conf:4: return 301 https://example.com$request_uri;
sample-files/apache/sites-enabled/example.conf:5: Redirect permanent / https://example.com/
sample-files/apache/sites-available/example.conf:5: Redirect permanent / https://example.com/
$ grep -RInE 'server_name|ServerName' sample-files/nginx sample-files/apache
sample-files/nginx/sites-enabled/example.conf:3: server_name example.com example.com;
sample-files/nginx/sites-enabled/example.conf:8: server_name example.com example.com;
sample-files/nginx/conf.d/admin.conf:3: server_name admin.internal;
sample-files/apache/sites-enabled/app.conf:2: ServerName example.com
sample-files/apache/sites-enabled/example.conf:2: ServerName example.com
sample-files/apache/sites-available/app.conf:2: ServerName example.com
sample-files/apache/sites-available/example.conf:2: ServerName example.com
View commands shown
These are the commands shown in the sanitized transcript.
Commands shown
grep -RInE 'return[[:space:]]+30[18]|rewrite[[:space:]]|Redirect[[:space:]]|RewriteRule|RewriteCond' fixtures/nginx fixtures/apachegrep -RInE 'server_name|ServerName' fixtures/nginx fixtures/apache
next steps
Related commands
Map Nginx Roots and Aliases
The URL was right. The filesystem path was not.
grep -RInE '^[[:space:]]*(root|alias)[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
List Nginx Listen Directives
The site was configured, but the port was not.
grep -RInE '^[[:space:]]*listen[[:space:]]' fixtures/nginx/conf.d fixtures/nginx/sites-enabled
Show Nginx Include Lines
The config was valid; it just was not included.
grep -RInE '^[[:space:]]*include[[:space:]]' fixtures/nginx/nginx.conf fixtures/nginx/conf.d fixtures/nginx/sites-enabled
Find Apache Document Roots
Apache was serving files from a different directory than expected.
grep -RInE '^[[:space:]]*DocumentRoot[[:space:]]' fixtures/apache/sites-enabled
Map Apache Proxy Rules
Apache was up. The reverse proxy target was wrong.
grep -RInE '^[[:space:]]*(ProxyPass|ProxyPassReverse)[[:space:]]' fixtures/apache/sites-enabled
Study mapping
Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.
Useful for
- LPIC-1 style command-line practice
- LFCS style performance tasks
- Linux+ style troubleshooting review
Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.