I am a beginner with Nginx and I've a question with a specific URL Rewriting.
I want "http://myserver.fr/context/[xxxxxxxxxxx]/synchronize.php" to redirect to /space/www/synchronize.php
And I want another URL type "http://myserver.php/context/[xxxxxxxx]" to redirect to /space/www/index.php
So I think the correct conf Nginx is :
location /context/ {
alias /space/www/;
rewrite ^(.*).synchronize.php /synchronize.php last;
rewrite ^/(.*)$ /index.php last;
}
As I am a beginner in Nginx, can you tell me if my idea is logical or not? Thanks a lot.
Related
I am having a small issue creating a dynamic sitemap.xml for the site.
My routing file:
Route::get('sitemap.xml', [
'uses' => 'PageController#sitemapXml',
'as' => 'user.page.sitemapxml'
]);
My controller:
public function sitemapXml(){
....
$content .= '</urlset>';
return response($content, 200)->header('Content-Type', 'text/xml');
}
My issue:
To access get the correct response i have to use the following route:
www.mysite.com/index.php/sitemap.xml
However, if i do www.mysite.com/sitemap.xml, i get a 404.
If i manually add the sitemap.xml file in my public folder, i can access the file i just added, but not the dynamic one created in my controller.
My research:
Its probably a problem with the server and not laravel itself. Apparently, .xml extension are not processed through the normal routing.
It suggests adding:
location = /sitemap.xml {
try_files $uri $uri/ /index.php?$query_string;
access_log off;
log_not_found off;
}
that did not work.
I also tried the changing my .htaccess to this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
as specified in the docs
My question:
Is their anything I can do laravel-wise to handle .xml requests?
Also, if you could guide me towards anything that might help me understand this process better, its very welcomed.
Thank you in advance for taking the time to help
UPDATE:
if instead of using my localhost, i use "php artisan serve", things work correctly without any issue.
I found the answer on this link:
https://laravel.io/forum/09-15-2015-removing-indexphp-from-url-laravel-5116
I changed my .conf file and voila.
Hope this helps you
Just to clarify: Nothing wrong with Laravel. More server specific.
I try to make specific rewrite rules by .htaccess but i need help, its doesn't work.
This is my url :
http://mywebsite.net/aaa-bbbb/cccc
aaa = dynamic parameter ( [a-z] )
bbb = dynamic parameter ( [a-z] )
cccc = dynamic parameter but optionnal ( [a-z] )
And i want rewrite user to this url :
http://mywebsite.net/mydir/ccc?x=aaa&y=bbbb**
url still will http://mywebsite.net/aaa-bbbb/cccc on tabbar
i try this
RewriteRule ^([a-z]+)-([a-z]+)/([a-z]+)$ mydir/$3 [L]
but it doesn't work
thx !
To rewrite a request to
http://mywebsite.net/aaa-bbbb/cccc
internally to
/mydir/ccc?x=aaa&y=bbbb
you need such a rewrite rule:
RewriteEngine on
RewriteRule ^([a-z]+)-([a-z]+)/([a-z]+)$ /mydir/$3?x=$1&y=$2 [L]
Note: the above rule has the syntax to be used inside the http servers host configuration. If you really want to use a .htaccess style file instead you need to use a slightly modified syntax, since those files work on relative paths:
RewriteEngine on
RewriteRule ^([a-z]+)-([a-z]+)/([a-z]+)$ mydir/$3?x=$1&y=$2 [L]
You can spot the missing / in the rewrite goal. The .htaccess style file has to reside inside the folder holding the mydir folder for this to work. Also the interpretation of such files has to be enabled at all in the http server configuration for.
A general note: .htaccess style files are notoriously error prone, hard to debug and they really slow down the http server for nothing. They are only offered as a last option for those not having access to the http servers host configuration. So for example for cheat shared hosting providers. In general you should always prefer to place such rules inside the host configuration itself.
I want to make the following url in nginx
comments.php?id=34
becomes
/comments/34
/comments/34/
I am trying with this and it works
rewrite ^/comments/$id/(.*)$ /comments.php?id=$1? last;
My Question is, how to do I force redirect comments.php?id=x to /comments/id
rewrite ^/comments.php$ /comments/$arg_id? permanent;
According to the documentation, "rewrite operates only on path, not parameters."
Try this instead:
if ($args ~ id=(.+)){
rewrite comments\.php /comments/$1 last;
}
we've been running a test verions of our site at www.mystie.com/test/ and these urls are being used by everyday people... how can i configure httpd.conf to now redirect all these old urls to the / location?
ie,
www.mysite.com/test/image1.jpg
should be:
www.mysite.com/image1.jpg
There are other httpd conf rules in there, so i assume i 'll have to place this up front
Just add these lines:
RewriteEngine on
RewriteBase /
RewriteRule ^test/(.*)$ /$1 [R=301,NC,L]
If lines 1 and 2 have already been set, then you can omit those.
If you prefer, you can add this into your .htaccess file in the root web directory instead. Slightly slower, but saves restarting httpd.
I guess you would need a 301 redirect (which should help in SEO as well)
Redirect 301 /test/ /
Looks like #melkamo has the .htaccess covered.
The alias_module will allow you to do it in httpd.conf
`Redirect permanent /test http://localhost`
It will erase test from the URL if it is the first subdirectory
HI,
Given the following apache/mod_rewrite rule taken from .htaccess within minify directory on the server:
RewriteRule ^([a-z]=.*) index.php?$1 [L,NE]
what will be the nginx compatible equivalent of it? I have tried:
rewrite ^/minify/([a-z]=.*) minify/index.php?$1 break;
but that doesn't seem to work.
Any ideas guys?
I have something like this and it's working for me
rewrite ^/min/([a-z]=.*) /min/index.php?$1 last;
Try something more like bbPress's code.