htaccess

I have a link that toggles an initially closed form (jQuery).

<a href="#" id="myform" class="show_hide">Contact Me</a>

I also attached an anchor to the form action so when the page reloads to show any errors they are kept in view instead of the page going back to the top and thus the visitor would not see the errors.

action="/contact.php#error"

So far this all works fine.

Now, using an .htaccess file I’m removing the file extension and adding a trailing slash.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

The problem is when the .htaccess file is added to the mix, it causes the toggle to open on load and remain open. I thought it might have to do with the anchor but that doesn’t seem to be it. Ideas?

Todd


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That doesn’t sound like anything that the htaccess could affect, not unless the JavaScript is reading the hash from the page and using that to decide whether or not to show the DIV.

Could you try setting action="/contact/#error" and see if that works? Then you could rule out the htaccess, because you’re simply setting the URL to what the redirect is doing anyway…

Walter

On Feb 14, 2012, at 12:06 PM, Todd wrote:

I have a link that toggles an initially closed form (jQuery).

<a href="#" id="myform" class="show_hide">Contact Me</a>

I also attached an anchor to the form action so when the page reloads to show any errors they are kept in view instead of the page going back to the top and thus the visitor would not see the errors.

action="/contact.php#error"

So far this all works fine.

Now, using an .htaccess file I’m removing the file extension and adding a trailing slash.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

The problem is when the .htaccess file is added to the mix, it causes the toggle to open on load and remain open. I thought it might have to do with the anchor but that doesn’t seem to be it. Ideas?

Todd


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Could you try setting action="/contact/#error" and see if that works? Then you could rule out the htaccess, because you’re simply setting the URL to what the redirect is doing anyway…

That was my thinking too and I tried it earlier but oddly it didn’t work. I must be missing something obvious.

Todd


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

It appears the problem is this:

Without .htaccess the toggle link looks like this,

http://somesite.com/contact.php#

or

<a href="#" id="contact" class="show_hide">Contact Me</a>

javascript

$('.slider').hide()
	$('a#contact').click(function() {
		$('.slider').slideToggle('400');
		$(this).text($(this).text() == 'Contact Me' ? 'Hide' : 'Contact Me');
		return false;
	});

But with .htaccess in place it now looks like this:

http://somesite.com/contact/#

It breaks the js obviously. I should have caught it. I can try changing the js syntax but I suspect it won’t work.

Todd


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I don’t know anything about how the jQuery library works internally, but I don’t see anything about this that would indicate that this is your problem directly. Do you get an error in your JavaScript console when you click?

http://scripty.walterdavisstudio.com/toggle/#

http://scripty.walterdavisstudio.com/toggle

http://scripty.walterdavisstudio.com/toggle.html

(Those are all the same URL, really, but Apache content negotiation is filling in the gaps here. I’m not using your htaccess per se, but it’s a very similar thing.) Note that I am explicitly canceling the click with preventDefault(), returning false is belt and suspenders. Prototype’s Event.stop() does both.

Walter

On Feb 14, 2012, at 2:08 PM, Todd wrote:

It appears the problem is this:

Without .htaccess the toggle link looks like this,

http://somesite.com/contact.php#

or

<a href="#" id="contact" class="show_hide">Contact Me</a>

javascript

$('.slider').hide()
	$('a#contact').click(function() {
		$('.slider').slideToggle('400');
		$(this).text($(this).text() == 'Contact Me' ? 'Hide' : 'Contact Me');
		return false;
	});

But with .htaccess in place it now looks like this:

http://somesite.com/contact/#

It breaks the js obviously. I should have caught it. I can try changing the js syntax but I suspect it won’t work.

Todd


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks for the examples. I got it sorted out (mostly) except for one issue.

[See the code I posted earlier in the thread for specifics]

What’s odd is there are 8 otherwise identical forms (each with different ids) that work but this last one doesn’t. Instead of the form reloading to the error anchor it goes to the top of the page.

Here’s the difference I’m seeing:

If I submit an empty form the errors come up as expected and the url looks like this:

http://somesite.com/who.php#form1error

This is good.

But the bad form looks like this:

http://somesite.com/who.php#form2error%20method=

I don’t know why the “%20method” part is being tacked on. PHP or javascript?

Todd


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I got it sorted out (mostly) except for one issue.

Had a db issue. It’s ok now.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options