简体   繁体   中英

how to correct rewrite nginx + apache urls

I have website (frontend - nginx, backend - (apache+php) ), this is nginx config file

server {

listen *:80;
server_name website.plus www.website.plus;
access_log /var/log/nginx/access.log;
location / {
proxy_redirect          off;
proxy_pass http://127.0.0.1:81/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 180;

}

}

apache

<VirtualHost 127.0.0.1:81>
        ServerName website.plus
        ServerAlias www.website.plus
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/website

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

and have this web urls

website.plus/tag.php?tag=cat
website.plus/search.php?search_content=cat
website.plus/view.php?image=LhUId4avpxVZK

please help me, how I can change (rewrite) urls to

website.plus/tag/cat
website.plus/search/cat
website.plus/view/LhUId4avpxVZK

Thank you

Try this (untested):

rewrite ^tag.php?tag=(.*) tag/$1;
rewrite ^search.php?search_content=(.*) search/$1;
rewrite ^view.php?image=(.*) view/$1;

I think it's clear (with documentation of nginx's rewrite ) but if you have a question please ask!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM