Category Archives: anchor

Why does href="/" direct to the system files?

When I request the page on the hosting device it directs me to the local system files. If I request the page from a different device it returns the correct index.html page. This is the anchor element being used for the request.

<a id="indexLink" href="/"><img src="images/logo.png" /></a>

Why is the host machine directed to the system files?

How to add a slash or why it isn’t added?

I am currently using Bootstrap to add an accordion function to a jobs page on a new website. Everything works fine, however when I click to view a specific accordion to display the listing, the URL only works like this: website/jobs#developer and not like this: website/jobs/#developer which would look a lot more professional on job boards and maintain what we have on our current site.

I don't want to have to go back to every link distributed and remove the slash. I am attaching what I have done in my htaccess but I am not sure its is affected by it. Please help!

<IfModule mod_rewrite.c>
    RewriteEngine On
    ErrorDocument 404 /views/errors/404.php
    RewriteRule ^(jobs|Jobs|JOBS)$ views/jobs.php [L]
</IfModule>

Redirecting old anchor links to new anchor links

I'm overhauling a website that someone else built for my organization. It was originally set up with "not so great" anchor links which included spaces. I have replaced those anchors with new ones that will work better.

Example: One of the old anchors looked like this /course/#To Have which browsers would luckily convert to /course/#To%20Have. I changed that anchor to this: /course/#to-have.

I'm now wanting to make sure that any anchors that may have been shared on social media or that could be linked to from other websites still work; I was planning on doing this via redirect in the .htaccess file, such as this one:

Redirect 301 /course/#To%20Have /course/#to-have

After some research I've found that this is not possible due to the # in the URLs. And I also have not seen examples where an anchor was redirected to another anchor.

Is this possible?

Static single page site, removing anchors

I have a static single page website, however I'm trying to figure out how to "link" to each section of the page giving a unique URL and being able to show in the browser history.

I don't even know where to start - I tried .htaccess with:

RewriteEngine On
RewriteRule   ^services/?$ /index.html#services [NE,R]

However the URL updates with the # rather than keeping the /services/ link (although it does redirect correctly).

Clearly this isn't the solution because

  • It adds the hash back to the URL
  • Does not show in users browser history properly

Html anchors in apache rewrite engine not working with NE flag

There is a solution to avoid escaping characters when URL are rewritten by Apache : the NE flag.

My problem is that it seems not to work for me, and I am also looking for a way to insepc the final URL (the one after the redirection).

My htaccess is :

RewriteEngine On
RewriteRule ^carte       /offers.php?#promo_code [NE]

I tried to reach the adress, and the anchor is working well (http://localhost:8888/offers.php#promo_code => this works well !)

But when I use http://localhost:8888/carte it redirects to offers.php page, not the anchored element.

Any idea ?

Friendly URL and Anchors

Im' trying to achieve that the document goes to the anchor name given with a friendly URL.

RewriteRule ^files/page/([a-zA-Z0-9\-]+)?$ myPage.html#$1

But this doesn't works.

I tried it inserting the url with the page: myPage.html#myAnchor and worked fine. So the problem must be in the htaccess line.

I searched and found this old question with an answer that seems it works, but unfortunately not for me.

HTACCESS file (updated with [L] flags):

AddType text/x-component .htc

RewriteEngine on
RewriteBase /

RewriteRule ^ahorro/?$ ahorro-para-mi-futuro.html [L]
RewriteRule ^ahorro/como-es-nuestro-ahorro/([a-zA-Z0-9\-]+)?/?$ como-es-nuestro-ahorro.html#$1 [L]
RewriteRule ^ahorro/preparado-para-tu-jubilacion/?$ hasta-que-punto-estas-preparado-para-tu-jubilacion.html [L]
RewriteRule ^ahorro/ventajas-fiscales/?$ ventajas-fiscales.html [L]
RewriteRule ^ahorro/para-mi-futuro/([a-zA-Z0-9\-]+)?/?$ por-que-deberia-ahorrar-para-mi-futuro.html#$1 [NE,NC,L]

RewriteRule ^preparar-jubilacion/?$ preparo-mi-jubilacion.html [L]
RewriteRule ^preparar-jubilacion/calcula-tu-patrimonio/?$ calcula-tu-patrimonio.html [L]
RewriteRule ^preparar-jubilacion/calculadora-gastos/?$ calculadora-de-gastos.html [L]
RewriteRule ^preparar-jubilacion/disponibilidad-de-ahorros/?$ como-podre-disponer-de-mis-ahorros.html [L]
RewriteRule ^preparar-jubilacion/4-pasos-para-mi-jubilacion/?$ 4-pasos-para-planificar-tu-jubilacion.html [L]

RewriteRule ^vivir-jubilacion/?$ vivo-mi-jubilacion.html [L]
RewriteRule ^vivir-jubilacion/prioridades/?$ que-necesito-y-cuales-son-mis-prioridades.html [L]
RewriteRule ^vivir-jubilacion/disponer-de-mis-ahorros/?$ como-podre-disponer-de-mis-ahorros.html [L]
RewriteRule ^vivir-jubilacion/4-pasos-para-mi-jubilacion/?$ 4-pasos-para-planificar-tu-jubilacion.html [L]

RewriteRule ^encuentros/?$ encuentros-futuros.html [L]

RewriteRule ^calculadoras-y-simuladores/calculadora-ahorro/?$ calculadora-de-ahorro.html [L]
RewriteRule ^calculadoras-y-simuladores/calculadora-gastos/?$ calculadora-de-gastos.html [L]
RewriteRule ^calculadoras-y-simuladores/calcula-tu-patrimonio/?$ calcula-tu-patrimonio.html [L]

RewriteRule ^politica-cookies/?$ politica_cookies.html [L]

Rewrite rule .htaccess with anchor if condition

I'd like to make a rewrite rule that only operates if a specific term is found in the url.

So if the targetterm is target and the url is:
website.com/target/something/test/

I want it to become:
website.com/target/something/test/#anchor

But if the url is, for instance:
website.com/alternative/something/test/
I want nothing to happen.

Is there maybe someone who has a clou?

Thanks

How to change how links appear (hide anchor tags and ".html") on CSS or htaccess

I have some links and I want them to be shown under the same name on the browser. For example www.link.com/index.htm or www.link.com/#anchor to be shown as www.link.com

I have tried that using css by putting that:

 link.address.href = link.address.href.replace(/#.*/,'')

and

link.address.href = link.address.href.replace(/i.*/,'')

but it doesn't work. I cannot find the possible ways to do that. I can think of :

CSS way which is the easiest for me, JS but I am not that literate in this and htaccess file creation. Although I have to be careful because I am not sure which server I am going to use. Which one is the best?

What am I doing wrong with the css modification above?

Anchor links and form action to current page but with addition GET values in the URL

On a page called somepage.php, I have the following HTML. I might be changing the name of the file, so I would rather not hardcode somepage.php in the links and action attributes. I could do so serverside using PHP, but I do not wish to. The site is limited to a very select audience, and I am okay with a JavaScript/jQuery solution which doesn't degrade (assuming it requires little code to maintain) or some feature that is only available to modern browsers. I might be open to an Apache solution, however, this is a last choice.

Is this possible, and if so, how is it implemented?

EDIT. I don't think I was clear. How could I modify the below code so that functionality is identical, however, it doesn't include "somepage.php" in any of the anchor or form attributes.

<form action="somepage.php" method="post">
 <input type="hidden" value="controller_1" name="controller" />
 <!-- other stuff -->
</form>

<form action="somepage.php?controller=controller_2" method="post">
 <!-- other stuff -->
</form>

<a href="somepage.php?controller=controller_3">foo</a></li>


<a href="somepage.php?controller=controller_4&amp;bla=blabla">bar</a></li>

URL rewriting preserving anchor in apache

I am trying to url redirect this url :

article-keywords_x_y_z-109.php#anchor

to this

article.php?id_article=109#anchor

I have tryed both these rules, but it doesn't seem to work.

RewriteEngine On
RewriteBase /BAH/
RewriteRule ^article-([a-zA-Z0-9_-]+)-([0-9]+)\.php#([a-zA-Z0-9_-]+)$ article.php?id_video=$2#$3
RewriteRule ^article-([a-zA-Z0-9_-]+)-([0-9]+)\.php#([a-zA-Z0-9_-]+)$ article.php?id_video=$2#$3 [NE,R]

But it doesn't work...