Viewed   192 times

I have a rewrite in nginx or Apache for this address:

to a script like

How can I access this rewritten URL in PHP? Because, if I use $_SERVER['REQUEST_URI'] of course I get:


but I only want:


Is this possible? Thanx for help.

Upd nginx cnf

proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  listen 80;
  server_name domain.test;

  location /
    rewrite ^/(main|best|air)$ /core/feeds.php?act=$1 last;



In Nginx conf, we need to add user header with request_uri:

proxy_set_header request_uri $request_uri;

And read it in php:



for some reason nginx don't like symbol '_' in header name, don't know how it worked before, maybe something changed after nginx update. Now i'm using

proxy_set_header rewriteduri $request_uri;

and in php

Wednesday, December 21, 2022

Check if your apache installation has mod_rewrite enabled.

In its simplest form, the rule to accomplish what you want to do would be:

In your .htaccess

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^/?$ [R=301,L]

RewriteRule songs/(.*)/(.*)$ songs/index.php?name=$1&song=$2

But give it a read to the apache documentation as well as verify your configuration, and here you'd find some useful stuff as well

Hope that helps.

Monday, September 19, 2022

In the end I had the guy who manages the Apache proxy server to add ProxyPreserveHost On to apache2.conf and this enabled forwarding of HTTP_HOST (and SERVER_NAME) properly to the backend Apache server.

Thank you everyone for your suggestions, I'm sorry the problem ended up being something stupid that wasn't even in the scope of my question. If the Apache server I was working on did not have a proxy in front of it, most of your suggestions would have proven completely accurate.

Monday, November 28, 2022

Have it this way:

Options +FollowSymLinks
RewriteEngine on

# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !.
RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]

RewriteCond %{THE_REQUEST} /index.html [NC]
RewriteRule ^index.html$ /? [R=301,L,NC]

RewriteRule ^listen/$ /console/ [NC,L]

# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]

Test it after clearing your browser cache.

Saturday, December 24, 2022

The matches are zero based.

<action type="Rewrite" url="{R:1}" />

Won't work because you only have one match. You need:

<action type="Rewrite" url="{R:0}" />

Also, this won't work, because you can only match on the path below the site root.

<match url="^(?!https://).*" ignoreCase="false" />

It looks like you are checking for ssl. Try this instead:

      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTPS}" pattern="^OFF$" />
Wednesday, December 7, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :