how to rewrite in Nginx that the page can jump to another page, except for index page? - web

how to rewrite that the page can jump to another page, except for index page
such as
visit xxxx.com, nothing change, still visit xxxx.com
visit xxxx.com/ddddd, it will jump to blog.xxxx.com/ddddd
I try
location / {
rewrite /.+ https://blog.xxxx.com$request_uri permanent;
}
it's not work

Related

Using Rewrite Rule in .htaccess not working

I am trying to use Rewrite to display a nice SEO friendly url instead of an ugly one.
Ugly URL
https://domain.co/blog-detail?data=how-important-is-teeth-cleaning-for-kids
Pretty URL
https://domain.co/blog-detail/how-important-is-teeth-cleaning-for-kids
Here Ugly URL is using 'data' variable value to populate page HTML.
Rewrite condition used
RewriteRule ^blog-detail/([A-Za-z0-9]+)$ blog-detail?data=$1
^^This does nothing.

How to change a value in url - index to home - htaccess

I have an index.html file and in my htaccess, I have removed the .html so that something like www.xxx.com/index#about would work.
I have a question inregards to wanting to change the url so instead of showing index, it shows home. I changed index.html to home.html but that messed things up as it was looking for index.
Is there a way to set it in htaccess so that index is replaced with home in url?

How to redirect Hard Coded Urls to hard coded Urls without hitting errorAction?

I have almost one thousand links which I want to redirect when a request is made specifically to those URLs. e.g
Redirect http://serverAddress/app/2017/06/09/8-20-taraweeh/ http://serverAddress/app/prayer/8-or-20-Rakat-for-Taraweeh
I am trying this code in .htaccess file but the problem is that when I enter the Url, instead of hitting the .htaccess code it first hits the Yii app and check if the Url exists, if not exists(definitely does not exist) it takes me to the error page.
Now I cannot define a rule because as you can see the URL after the app is changing, I cannot define a generic rule. So I have to hard code in my yii2 app.
Question:
How to Hard code Url redirections in yii2?
You could define a rule something similar:
'<year:\d+>/<month:\d+>/<day:\d+>/<title>' => 'site/redirect'
Then in your SiteController use can use redirect in the controller action:
public function redirectAction($year, $month, $day, $title) {
$newUrl = .... // compute new URL based on the parameters
return $this->redirect($newUrl, 301);
}

htaccess not working properly for sub url having more slashes

I am having 2 websites. Call it 5p_front (http://localhost/5p_front/) (Developed in OctoberCMS) and 5p_group (http://localhost/5p_group/) (Developed in CakePHP)
In 5p_front i have an .htaccess file and in which i put a condition which will redirect to 5p_group website as soon as it finds a word having 5p_group_login in url. Here is code below
.htaccess
RewriteRule ^5p_group_login.*$ http://localhost/5p_group [L,R=301]
So if someone tries to go here for example http://localhost/5p_front/5p_group_login , they will simply be redirected to here http://localhost/5p_group/ .
This works fine from home page and other subpages like about page for example http://localhost/5p_front/we-are-5p-group .
However i have one product inner page http://localhost/5p_front/product/10 and if i hover the menu item which allows me to redirect to login page, it is showing this url http://localhost/5p_front/product/5p_group_login and hence when i click on it, i am unable to redirect at http://localhost/5p_group/ as it is only recirecting to this current url only http://localhost/5p_front/product/5p_group_login which should not be the case.
Additionally, My Menu is coming dynamically and i have used Static Pages plugin to create menus which OctoberCMS provides and i have created "Login" menu link like below.
How can i redirect the url at http://localhost/5p_group/ even if the user is at http://localhost/5p_front/product/10 and clicks on "Login" link which is showing http://localhost/5p_front/product/5p_group_login if i mouse hover on it.
Can someone guide me here what should i do in this scenario.
Thanks
Your rule
RewriteRule ^5p_group_login.*$ http://localhost/5p_group [L,R=301]
when placed in 5p_front/.htaccess will affect only URIs that begin with /5p_front/5p_group_login (because of the leading ^ in your pattern) so /5p_front/product/5p_group_login will not match.
If you want to rewrite URLs that have 5p_group_login anyhwere, just use:
RewriteRule 5p_group_login http://localhost/5p_group [L,R=301]

Redirect parent not childs htaccess

In my magento module there is an extension.
Some urls like
http://www.domain.com/abc/p#abcs.html
http://www.domain.com/abc/p#xyz.html
etc
But when browsing http://www.domain.com/abc/p -> lead to blank page
I do not need http://www.domain.com/abc/p url
Is anybody help me
I want to redirect the url http://www.domain.com/abc/p to 404 page
without affecting its childs
ie
1. http://www.domain.com/abc/p#abcs.html
2. http://www.domain.com/abc/p#xyz.html
Points to its current position and
http://www.domain.com/abc/p to 404
Any help apperciated
Based on your comment it seems http://www.domain.com/abc/p#abcs.html shows proper content but http://www.domain.com/abc/p shows blank page.
In that case you can't do that via .htaccess because on server side URL will always be: http://www.domain.com/abc/p.
You need to put some custom Javascript in your page and redirect to some non-existant page (resulting in 404) by checking location.href using your Javascript.

Resources