Rewrite rule in nginx error - nginx

What is wrong in this rule?
rewrite ^/view/?([^/.]+)?/?([^/.]+)?.html /view_video.php?id=$1 last;
I changed from:
RewriteRule ^view/?([^/\.]+)?/?([^/\.]+)?\.html view_video.php?id=$1 [L,QSA]
My link must be:
./view/14/name_of_video.html

Related

Rewrite page url as subdomain in apache htaccess

I have a lot of page URLs like domain.com/page I want a rewrite rule that will change all my pages URLs as page.domain.com meaning whatever will come after the domain just rewrite it as a subdomain
example urls
expertpro.cloud/hot-to-write-blog to hot-to-write-blog.expertpro.cloud
expertpro.cloud/game to game.expertpro.cloud
expertpro.cloud/nibm-full-form to nibm-full-form.expertpro.cloud
expertpro.cloud/choclate to choclate.expertpro.cloud
expertpro.cloud/harmony-in-life to harmony-in-life.expertpro.cloud
expertpro.cloud/paki-cold-places to paki-cold-places.expertpro.cloud
expertpro.cloud/you-are-one to you-are-one.expertpro.cloud
I already have some code for Nginx
The empty location = / block is necessary so that you don't redirect
http://example.com/ to http://.example.com/.
//replacing domain name in rewrite rule
location = / {
# don't redirect $server_name/
}
location / {
rewrite ^\/([^\/]*).*$ https://$1.$server_name/ redirect;
OK, all you need is an internal rewrite, as it looks:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule ^ /%1%{REQUEST_URI} [END]
You obviously need the rewriting module to be loaded into your http server.
That would be a variant which additionally redirects direct requests to the internal URL:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^/?([^/]+)(/.*)?$ https://$1.example.com$2 [R=301]
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule ^ /%1%{REQUEST_URI} [END]
Here it makes sense to start out with a R=302 temporary redirection and only to change that into a R=301 permanent redirection once everything works as expected.
In general you should try to implement such rules in the actual http server's host configuration. If you have no access to that you can instead use a distributed configuration file (".htaccess"), but those come with disadvantages. You need to enable the interpretation of such files in that case.

Lumen in a subfolder trailing slashes issue

In public/index.php I have changed $app->run() to $app->run($app['request']) and this resulted in Lumen working in a sub-folder, so this works:
http://local.dev/app/
http://local.dev/app/test
However if there's a slash at the end of a route then I get a NotFoundHttpException. For example:
http://local.dev/app/test/
I'm using NGINX and my rewrite rule for the folder is:
location /app/ {
try_files $uri $uri/ /app/index.php?$query_string;
}
Am I doing something wrong?
If laravel is in a sub-directory use this :
RewriteRule ^(.*)/$/ /$1 [L,R=301]
instead of this:
RewriteRule ^(.*)/$ /$1 [L,R=301]

removing just "?m=1" from url using rewrite rule

just few day before i had migrated my blogger blog to wordpress. Now i find crawn error with many url, at the end of many url the name and value is there (?m=1) which shown as a 404 error now i want to redirect all the url additing .htaccess file
example:
http://www.tipsviablogging.com/blogger-tricks/facebook-disqus-tab-in-blogger.html?m=1
musy redirect to
http://www.tipsviablogging.com/blogger-tricks/facebook-disqus-tab-in-blogger.html
any one is having expertise in url rewrite kindly help me...
I haven't got a test system handy, but something like this in your .htaccess should do the trick:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^m=1$
RewriteRule ^(.*)$ /$1? [R=301,L]
If memory serves, you need the ? at the end of the target in the RewriteRule to stop the original query string being appended.
The code assumes you haven't got any other parameters (eg it won't work if you have ?m=1&foo=bar).
I want to add a solution on NginX:
Use below code in "location /" Of VirtualHost config
if ($query_string ~ "^m=1$"){
rewrite ^(.*)$ /$1? redirect;
}

Rewriting entire uri as querystring using nginx?

How do I rewrite URIs of the form
http://domain1/one/two?three=four
to
http://domain2?path=http%3A%2F%2Fdomain1%2Fone%2Ftwo%3Fthree%3Dfour
using nginx?
rewrite ^(.*)$ http://domain2?path=$scheme://$host$1 last;
OR
rewrite ^(.*)$ http://domain2?path=$scheme://$host$reques_uri last;
More on nginx variables.

Map Domain Alias to Virtual Folder in IIS6

How could I go about mapping a domain alias, e.g. domainAlias.co.za, to a virtual folder under, e.g. mainDomain.co.za, so that all requests to domainAlias.co.za actually get served by mainDomain.co.za/domainAlias ?
A URL Rewriter like IIRF lets you do this.
The rules would be:
RewriteCond %{HTTP_HOST} ^(?!mainDomain)([^\.]+)\.co\.za$
RewriteRule ^/(.*)$ /%1/$1 [L]
In English, this rule says: if the host is NOT maindomain.co.za, but still ends in .co.za, then rewrite the URL so that it is prepended with /domainAlias/. With this rule, you get:
input output
----- ------
http://foo.co.za/a.php http://main.co.za/foo/a.php
http://foo.co.za/a.aspx?r=1 http://main.co.za/foo/a.aspx?r=1
You can also go one level further and make the rewrite conditional on the presence of the directory, something like this:
RewriteCond %{HTTP_HOST} ^(?!mainDomain)([^\.]+)\.co\.za$
RewriteCond c:\wwwroot\%1 -d
RewriteRule ^/(.*)$ /%1/$1 [L]
This says: if the host is not maindomain.co.za, AND the directory c:\wwwroot\domainAlias exists, then rewrite to prepend ....
But in that case you might instead want to do the converse - test for lack of existence of the directory - and redirect to a 404:
RewriteCond %{HTTP_HOST} ^(?!mainDomain)([^\.]+)\.co\.za$
RewriteCond c:\wwwroot\%1 !-d
RewriteRule ^/(.*)$ - [NF]
NF = 404
you can also do [F] which is a 503 (Forbidden).
IIRF works on IIS5, IIS6, or IIS7.
I haven't used it, but IIS has a URL Rewrite Module that can import Apache mod_rewrite rules. There is also a document that compares IIS URL Rewriting and ASP.NET routing. With some research, you should be able to get that working.
You can use routing.
System.Web.Routing

Resources