Welcome to WebmasterWorld Guest from 54.224.121.67

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

RewriteRule adding jquery # in URL

     
3:56 pm on Jun 18, 2014 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 20, 2004
posts: 48
votes: 0


Hello everybody;
I'm starting in mod_rewrite, as a way to improve my site ranks, of course. I've digged some useful informations in some old posts here in webmasterworld, so i didn't have to upset anyone with boring questions.
The deal is the follow:
My SSI (index.shtml) is calling <!--#exec cgi="cgi-bin/index.cgi" -->

and my .htaccess is the follow:



RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^index\.shtml$ index.html [T=/text/x-server-parsed-html,L]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^index\.html$ /cgi-bin/index.cgi [T=application/x-httpd-cgi,L]
RewriteRule ^/?([a-zA-Z_]+)$ /?lang=$1 [L]



Fine. What use to be my-domain.com/?lang=EN Should become my-domain.com/EN but it didn't. It is my-domain.com/EN#Ubg45brr that i belive is coming from the jquery. I say "believe" because never came up with the URL formed with parameters.
Why did that happen now and how can i remove it from the url now that i'm using mod_rewrite ?
Thanks for the help in advance.
5:39 pm on June 18, 2014 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:3451
votes: 182


Sometimes old answers can confuse things, did you get that here: [webmasterworld.com...] ? It is from 2001. I haven't seen one like this that I can recall.

Without even taking a real close look, I can see that your Rule order is reversed and the -s is where the first part of the Cond should be. To straighten it all out can you specify the actual filename and what you want to use instead?

I would need to go and look up the flags you have here, but if we can see what the real URL is and what you prefer to see instead, you may get help before I even finish looking for that. You don't need the entire http domain stuff, just the page's current URL and how you'd like it to be. Also if there are other rules preceding or following this one that could have an effect, that would help.
6:36 pm on June 18, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14256
votes: 551


What use to be my-domain.com/?lang=EN Should become

g1smd has a bit of boilerplate about how mod_rewrite can't "make" or "change" the URL. What's really glaring in the quoted set of rules is that none of them have the [R] flag; they're just [L]. If you want the URL to be different, it can only be done by forcing the visitor to make a new request. That's the [R] part. Rewriting is an entirely separate process.

:: detour to Apache docs as I'm fairly certain I have never seen [T] in my life ::

Oh, is that all.

In any case, why are you rewriting from shtml (the visible URL) to html (the source of the content)? That seems backward. You could conceivably rewrite in the other direction, from visible html to "real" shtml, if there are only a few files involved and you don't want to mess with the x-bit hack. Otherwise there's no point.

If you want shtml in the visible URL, why not just leave the physical files that way? I strongly suspect you've misunderstood rewriting so everything is simply backward.

Sanity-saving suggestion: Leave a blank line between rulesets, i.e. after each RewriteRule. mod_rewrite doesn't care, but it makes it a lot easier to read.


A thread from 2001 could be perfectly reliable if it pertains to Apache 2.x. Cursory research suggests that 2.0 began showing up around 2000. So a thread from 2001 probably does concern 1.3 unless the thread explicitly says it's about 2.0.


The OP explicitly says .htaccess, meaning it isn't your own server. Have you verified that SSIs work if you do everything by default means, .shtml extension and so on?
11:16 am on June 19, 2014 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 20, 2004
posts: 48
votes: 0


not2easy- yes, that's the thread i got if from.
There are no other rules preceding or following those yet.
Like i mention, it's the first time i'm really looking at mod_rewrite and it is basically chinese. I've done a bit of reading and i admit that my english is getting worst by the day and some tutorials appear to contradict itself. There is a lot of stuff out there that i've tried and didn't work for my situation. The example code above is the only thing close to what works (badly I know).


lucy24- About the [R] haven't got close to that.
About the [T] there is always the first time. It exist and it works, Why ? i wish i would know.
The fact is, that i don't really know what's written, it was a bit of sample code and a lot of try outs. I was sort of happy with my small success, but now i can see it just nonsense.
It would be much easier, i guess, if my index was in the domain root, but it isn't and all the attempted with what seems to be a straightforward rules didn't work.
Tell me guy, how should i start ?

Thank you for your posts.
2:53 pm on June 19, 2014 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:3451
votes: 182


The .htaccess file you are using as shown above is located in the /somedirectory/ folder, is this correct? I'm guessing because you said "if my index was in the domain root, but it isn't".

Sorry if I am dense on the what and where here, this is a page at http://example.com/somedirectory/index.shtml and you want anyone who requests that URL to end up at a page called http://example.com/(lang-setting) - is this correct? I'm just trying to get the basics straight because the URL you mention with the language reference is in the root directory, but you said the index.shtml is not in that directory.

You said there are no other rules in htaccess either before or after these rules, so there is no rule if someone requests http://www.example.com/somedirectory/index.shtml - you should have a rule for HOST somewhere.

One contributing error could be the underscore after the Z here: [a-zA-Z_] that could have it looking for E_N instead of EN or ES or other Language setting.
7:02 pm on June 19, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14256
votes: 551


I think what you should do at this point is step back and figure out what you want to have happen:

"When the user requests X, the browser's address bar should show Y, while the page shows content that lives at location Z."

Lay this out in English. Don't even think about RewriteRules until you know exactly what you want a rule to do.

I strongly suspect the [T] flag isn't the most appropriate way to achieve the desired result. We need someone here who speaks Apache. (phranque? Where'd you go?)
9:39 am on June 24, 2014 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 20, 2004
posts: 48
votes: 0


Sorry for late reply.
not2easy - Not like you think. The index is /home/user/www/index.shtml side by side with .htaccess. The script is at /home/user/www/cgi-bin/index.cgi.
mention in the first post, the index.shtml just contain <!--#exec cgi="cgi-bin/index.cgi" -->
Also the "_" in [a-zA-Z_] was not a problem. But i'm away from all that now.


lucy24 -

"When the user requests X, the browser's address bar should show Y, while the page shows content that lives at location Z."

Not really

"When the user requests X, the browser's address bar should show Y, while the page shows content that lives at location X."



I've reset everything i've read about mod_rewrite and my .htaccess looks like the follow now:


RewriteEngine On
RewriteBase /
DirectoryIndex /cgi-bin/index.cgi
RewriteRule ^([a-zA-Z]+)/?$ ?lang=$1 [L]
RewriteRule ^([a-zA-Z]+)/([a-zA-Z-]+)/?$ ?lang=$1&sec=$2 [L]


I've got rid of the index.shtml and apparently that's what i was looking to accomplish, apparently ....
Now my-domain.com/EN/CONTENT or my-domain.com/EN/ shows relative paths to every file and i was not expecting that. It is a massive job to change all paths in my scripts.
Is there a way of going around this?
6:43 pm on June 24, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14256
votes: 551


"When the user requests X, the browser's address bar should show Y, while the page shows content that lives at location X."

That's why I refer to the rewrite/redirect two-step. You see, it makes no difference whether the content actually lives at the URL the user originally requested. Once a user has been redirected, fetching the content becomes an entirely separate process. It may make it a little easier to code, because the pretty URL and the "real" location are each deducible from each other. But you still need two separate sets of rules: first one for the external redirect, and then one for the internal rewrite.

If it's a brand-new site where the "real" (long, ugly, complicated) URL has never been publicly visible, you may be able to omit the redirect. But keep an eagle eye on logs to make sure nobody ever asks for this form.
5:33 pm on June 29, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


The latest code promotes duplicate content. The trailing slash should not be optional. Pick one format and link to that format as the canonical version from the pages of your site. Set up a redirect to redirect the other format to the canonical format. Set the rewrite the respond only to requests for the canonical format.
7:52 pm on June 29, 2014 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14256
votes: 551


The trailing slash should not be optional.

I should repeat here something I learned only by direct personal observation: Even if your own URLs and internal links use only one form or the other-- for example if a trailing slash represents a real, physical directory-- search engines will periodically ask for the same URL without final slash. When you're dealing with physical directories, you need take no action because mod_dir is on top of it. If the URLs are created by a CMS you need to make sure the redirect takes place.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members