I've got this RewriteRule, And I can't make it work with nginx :
RewriteRule ^/espace-annonceurs/##contenu-des-espaces-annonceurs http://mywebsite.com/##contenu-des-espaces-annonceurs [L,P]
The Proxy is because it make an ajax request.
I've tried a lot of things, with location, proxy_pass, rewrite, and so on...
Thanks by advance.
Actually you need proxy request to your host to some other host. That's job for proxy module. The simplest config would be like this:
location /espace-annonceurs/##contenu-des-espaces-annonceurs {
proxy_pass http://mywebsite.com/##contenu-des-espaces-annonceurs;
}
Probably you'll need some proxy_set_headers directive.
Read documentation http://nginx.org/r/proxy_pass.
So a simple rewrite would do.
rewrite ^/(espace-annonceurs/##contenu-des-espaces-annonceurs)$ http://example.com/$1;
Related
I'm trying to convert this apache ReWriteRule to NGINX but it doesn't seem to be working.
Apache Rule: RewriteRule ^([A-Za-z0-9_-]+)\.php$ index.php?pagename=$1 [NC,QSA]
NGINX (not working): location / { rewrite ^/([A-Za-Z0-9_-]+)\.php? /index.php?pagename=$1; }
I do have the NGINX rule in a location block.
What am I missing here? I looked at the other similar questions but didn't find enough suitable clues to solve the problem. Thanks for the help.
Using converter:
server {
server_name example.com;
rewrite ^/([A-Za-z0-9_-]+)\.php$ /index.php?pagename=$1;
}
And indeed, many rewrites are easier with just a rewrite placed in the server {} context (no need for extraneous location).
I currently have a rewrite.config file with the following: RewriteRule ^/abc /docs. This successfully directs clients to the docs webapp, but I would still like the client to see localhost/abc in their browser.
In Apache mod_rewrite, this would be handled by simply adding [PT] to the end of the rewrite rule.
Any suggestions?
Thanks,
Brandon
I would suggest using the Tuckey UrLRewriteFilter. It appears to have better documentation and offer more flexibility than Tomcat's Rewrite value.
Following the accepted answer to this post, I constructed a rewrite rule which is pretty straight forward, but doesn't seem to work as designed.
# /st doesn't exist, it's virtual
example.com/st/sometext
Rewrites to
# /app is a symlink to /app.php, and this link works if entered directly
example.com/app/st/sometext
And the rewrite rule:
RewriteRule ^st/(.*)$ app/st/$1 [L]
This rule is at the top of the rewrite block, after which there are other rules, but those rules shouldn't apply, due to the [L] constraint.
The rewrite log file has this:
(2) init rewrite engine with requested uri /st/sometext
(1) pass through /st/sometext
It doesn't seem like the rewrite rule is matching the url. What am I missing?
Ok, I resolved the issue by switching over to nginx (lol) and implementing this rewrite rule:
location /st {
rewrite ^/st/(.*)$ /app.php/st/$1 last;
}
The switchover to nginx really had little to do with the rewrite rule and more to do with getting away from apache 2.2 (default upstream version for centos), however with nginx, rewrite rules are more straight forward than apache's (imo).
I'm trying to figure out how to re-write urls using nginx in front of an apache.
I am new to a set up like that and after an extensive research I couldn't figure it out.
I am trying to enable seo friendly urls in a prestashop 1.6.0.6 installation without any luck. The truth is that this is really straightforward when using only an apache as a web server.
I would appreciate it if someone could help me on this.
Whether this will work depends on how your Apache server is configured to accept the URLs. If Apache is configured, as you mentioned with a .htacess file, to serve at the root of the host name, then rewriting may not be required. An example Nginx server block like this:
server {
server_name nginx.example.org;
location / {
proxy_set_header Host $host;
proxy_pass http://apache.example.org:80 break;
}
}
will pass the exact host and path being accessed from Nginx through to Apache without any changes. The server_name and proxy_pass directives will need to be changed for your local configuration, however. In this case, because of the use of the location / {}, all paths are accepted and proxied.
As long as the backend Apache is configured correctly and accessible from Nginx, this should work. The best test would be to ensure that you can access resources on Apache directly first, especially those with the SEO-friendly URLs, which would indicate the .htaccess file is in working and effect. Then configure Nginx in front as per the above.
As for potentially using only Nginx, you could port the rules from the .htaccess over into rewrite directives within Nginx configuration. In my experience, the rules are very similar in functionality and structure:
Apache: RewriteRule ^/(.*\.jpg)$ /images/$1 [L]
Nginx: rewrite ^/(.*\.jpg)$ /images/$1 last;
More information is at the Nginx wiki.
I need to do the following on my apache webserver :
Redirect any URL starting with :
http://mydomain1.com/archive
to
http://mydomain2.com/archive
Is there a way using mod-rewrite or RewriteEngine to disguise that URL, so that the URL that appears in the browser is mydomain1.com ? I don't want to give away the fact that we are switching servers.
you could try a reverse proxy. This will allow you to take one url and forward the request to another server without the end user knowing.
Try adding this in the .htaccess from domain1.com/archive
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule (.*) http://mydomain2.com/archive [P]
</IfModule>
Edit: Tell me if you've tried this and if it worked or not.
That's not possible using mod_rewrite. If host changes then it has to be an external redirect using R flag.
A possible workaround is to make server to server call from inside your code on mydomain1 to mydomain2. If using php you can use file_get_contents function to make this happen.