Ad

Htaccess Not Working Properly For Sub Url Having More Slashes

- 1 answer

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.

enter image description here

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

Ad

Answer

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]
Ad
source: stackoverflow.com
Ad