.htaccess redirect loop when trying to transform last part of URL to fragment

Michael

I have the following rule in my .htaccess file.

RewriteRule ^(segment1|segment2)/(.*)$ $1/#$2 [R=301,NE,L]

The intent is to prepend a # to the last part of the URL. But I run into a redirect loop issue. I don't know why as I applied L flag.

What I want to achieve is, for example:

Turn:

http://example.com/segment1/test

into:

http://example.com/segment1/#test

Any advice would be much appreciated!

Thanks!

jacouh

This is tested in Debian/Apache2:

RewriteEngine On
RewriteRule ^(segment1|segment2)/([^#]+)$ /$1/#$2 [R=301,NE,L]

The [L] flag only ends the current run of rewrite, as URI changes, it will continue to rewrite, so you've an infinite loop.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

redirect .htaccess - remove last part of url

.htaccess redirect URL last part to same URL query strings value?

Redirect htaccess part of url

Need to redirect last part of url using htaccess with parameters

htaccess - redirect removing part of url

.htaccess redirect based on a part of URL

.htaccess redirect only working for part of the URL

Change and remove a part of url with redirect 301 (htaccess)

remove a specific part from url with htaccess and redirect

Capture the last subfolder of the URL to redirect using htaccess

How to remove last part of my URL with .htaccess?

htaccess rewrite - removing the last part from url

Htaccess 301 redirect by stripping part of string url to correct url

.htaccess redirect when URL contains parameters

.htaccess redirect only homepage, not when parameter in URL

Redirect all urls after replace a part of url htaccess

.htaccess - check if part of URL is missing - 301 redirect for ajax URLS

How to 301 redirect by changing part of a dynamic url in htaccess

. htaccess - redirect to subfolder with HTTPS while hiding URL part

Redirect ?catid=0&id= part of URL using Regex and .htaccess

How to redirect to clean URL (remove last hypen) with RewriteRule in .htaccess

trying to catch all conditions for URL redirect in htaccess file

Htaccess Redirect Loop Issue

htaccess redirect stuck in loop

htaccess causing redirect loop

Redirect URL when last character of URL matches a regex

How to redirect from last fragment to specific fragment on last fragment backpress

WordPress - Forcing SSL with .htaccess leads to redirect loop when using Polylang

.htaccess dynamic URL redirect