homepage Welcome to WebmasterWorld Guest from 54.226.93.128
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

This 113 message thread spans 4 pages: < < 113 ( 1 [2] 3 4 > >     
Trailing slash
qimqim




msg:4647303
 11:47 pm on Feb 20, 2014 (gmt 0)

Very big, small problem... which I can't solve.

I have a login procedure in my site. from some of the pages after a successful login the visitor is redirected to the page he was viewing. All works fine except that when the page opens it has a slash at the end and the page does not sisplay properly until manuall you delete the slasj from the url

How can I do this in htaccess?

I tried RewriteRule ^(.*)/+$ $1 [R=301,L]
but got this:
http://example.net/home3/pintotou/public_html/Asia/Indonesia/bali.php

instead of this, which is what I want:

http://example.net/Asia/Indonesia/bali.php

without the htaccess code I am getting

http://example.net/Asia/Indonesia/bali.php


Thank you for your help

[edited by: phranque at 9:30 am (utc) on Feb 21, 2014]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]

 

lucy24




msg:4648372
 9:27 pm on Feb 23, 2014 (gmt 0)

Lucy told me

Yes, but Lucy was talking through her hat, because she mixed up your own query with the referer's query. It's not a huge immediate issue, because the potential problem is just that-- potential. A number of other things would have to be true before a query in http:// could do something bad.

The most recently posted htaccess still has some serious issues. In particular

#1 all rules using mod_alias (Redirect by that name) must be converted to mod_rewrite syntax

#2 after you've done that, rules must be listed in order of severity. First the [F]s, then the [R]s, finally the plain [L]s. And never, ever have [NC] in a rule creating an internal rewrite, because that exposes you to Duplicate Content.

RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [L]


Is it possible that the [L] was a typo for [F]? Anyway, you don't need the .* since you're neither capturing nor anchoring.

Recurring query: Is that – really a - (hyphen)? It looks more like a dash, but it's hard to tell in a fixed-pitch font. I don't know whether Apache actually cares, since the whole point is "ignore the target, if any".

g1smd




msg:4648382
 10:14 pm on Feb 23, 2014 (gmt 0)

If you had numbered the rules when I asked, I would already have posted the correct order and a number of other specific issues to fix.

qimqim




msg:4648450
 6:41 am on Feb 24, 2014 (gmt 0)

Hi

Th reason I di not number them is that I did not understand how to do it. Should I

1.#redirect from www
RewriteCond %{HTTP_HOST} ^www.example\.net$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301,L]

or

#redirect from www
1.RewriteCond %{HTTP_HOST} ^www.example\.net$ [NC]
2.RewriteRule ^(.*)$ http://example.net/$1 [R=301,L]

lucy24




msg:4648469
 9:13 am on Feb 24, 2014 (gmt 0)

Oh, lord.

# 3 anything that is not an Apache directive MUST be in a "comment" line:

# 1
RewriteCond et cetera
RewriteCond et cetera
RewriteRule et cetera

# 2
RewriteCond et cetera
RewriteRule et cetera

...

# 75
RewriteCond et cetera
RewriteRule et cetera (this is the domain-name rule)

Gotta admit I don't personally number my rules. But it saves a world of aggravation when you're asking questions and quoting an htaccess file that involves more than two RewriteRules.

Now, if one could number rules along the lines of
RewriteRule[++count] ...

qimqim




msg:4648483
 10:20 am on Feb 24, 2014 (gmt 0)

Hi Lucy and g1smd

I'm out of prison! Back in the wwwide world!

Here goes my latest attempt at the htaccess. Could you tell me if it is correct, especially this business of Ls and Rs.

Thank you


# 1 Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php

# 2 Do not allow access to the directories
Options -Indexes

# 3
AddType text/x-component .htc

# 4 allow all except those indicated here
<Files *>
order allow,deny
allow from all

</Files>

#5 block visitors referred from indicated domains
RewriteEngine on
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymlinks

Options +SymLinksIfOwnerMatch

RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [L]

RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* – [L]

# 6 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [L,NC]

# 7 redirect from www
RewriteCond %{HTTP_HOST} ^www.example\.net$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]

# 8 redirects from file that vhanged name

Redirect 301 /Pinto/oldindex.html http://example.net/Pinto/oldindex.php
Redirect 301 /Asia/Indonesia/bali.html http://example.net/Asia/Indonesia/bali.php
Redirect 301 /Asia/Indonesia/indonesia.html http://example.net/Asia/Indonesia/indonesia.php

g1smd




msg:4648508
 12:04 pm on Feb 24, 2014 (gmt 0)

Comment 5 is in the wrong place. The next line doesn't do what the comment says.

Rule 5a and 5b - the L should be F.
Rule 5b - remove .* from Condition.

Rule 6 - the four conditions can be simplied to one,
!^http://(www\.)?example\.net [NC]
Rule 6 -
jpg¦jpeg can be simplified to jpe?g
Rule 6 - the L should be F.

Rule 7a and 7b have missing escaping and both rules are non-optimum in multiple ways.
Rule 7a - Condition pattern should be
!^(example\.net)?$
Rule 7b - needs fixes to both patterns, adding missing escaping of literal periods and replacing .* with
([^/]+/)* in both places.
Rule 7b - Condition pattern should begin
^[A-Z]{3,9}\ followed by a space then a slash and then the remainder of pattern.
Rule 7b - should be before Rule 7a.

Change rule 8a, 8b and 8c to use RewiteRule syntax with
[R=301,L] flags.
Rules 8a, 8b and 8c should be before Rule 7.

Fix up and renumber as 1 to 14.

[edited by: g1smd at 1:05 pm (utc) on Feb 24, 2014]

phranque




msg:4648521
 12:24 pm on Feb 24, 2014 (gmt 0)

RewriteCond %{HTTP_REFERER} !^http://example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net$ [NC]

you should only have internal referrals from your canonical hostname which is example.net so the www.example.net tests are unnecessary.
you can combine the remaining two into one rule that should suffice:
RewriteCond %{HTTP_REFERER} !^http://example\.net(/|$) [NC]

qimqim




msg:4648532
 12:34 pm on Feb 24, 2014 (gmt 0)

Hi

many thanks all

I did not change everything because I got confused and unsure about a couple of them. Addin the advice from phranque, this what I have now:

# 1 Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php

# 2 Do not allow access to the directories
Options -Indexes

# 3
AddType text/x-component .htc

# 4 allow all except those indicated here
<Files *>
order allow,deny
allow from all

</Files>


RewriteEngine on
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymlinks

Options +SymLinksIfOwnerMatch

#5 block visitors referred from indicated domains
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F]

RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]

# 6 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example\.net(/|$) [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

# 8 redirects from file that changed name

Redirect 301 /Pinto/oldindex.html http://example.net/Pinto/oldindex.php
Redirect 301 /Asia/Indonesia/bali.html http://example.net/Asia/Indonesia/bali.php
Redirect 301 /Asia/Indonesia/indonesia.html http://example.net/Asia/Indonesia/indonesia.php


# 7 redirect from www
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^([^/]+/)* index.html$ http://example.net/$1 [R=301,L]


RewriteCond %{HTTP_HOST} !^(www.example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301,L]

phranque




msg:4648533
 12:40 pm on Feb 24, 2014 (gmt 0)

okay so far - now go read g1smd's post and fix a few more things.

qimqim




msg:4648538
 12:50 pm on Feb 24, 2014 (gmt 0)

If you don't mind for now I'll keep Rule #8 as it is or I'm going to upsey someone else... I understand that it is valid as it is, simply could bemore elegant, right?

And I couldn't understand this part:

Rule 7a and 7b have missing escaping and both rules are non-optimum in multiple ways.
Rule 7a - Condition pattern should be !^(example\.net)?$
Rule 7b - needs fixes to both patterns, adding missing escaping of literal periods and replacing .* with ([^/]+/)* in both places.
Rule 7b - Condition pattern should begin ^[A-Z]{3,9}\ followed by a space and then the remainder of pattern.

qimqim




msg:4648543
 12:58 pm on Feb 24, 2014 (gmt 0)

#8 was given to me by a good friend I don't want to lose. let me speak to her first...

Rule 7b - Condition pattern should begin ^[A-Z]{3,9}\ followed by a space and then the remainder of pattern

I think #7b is now #7a. Should it be like this?

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^[A-Z]{3,9}\ index.html$ http://example.net/$1 [R=301,L]

qimqim




msg:4648545
 1:09 pm on Feb 24, 2014 (gmt 0)

Deleted

[edited by: qimqim at 2:20 pm (utc) on Feb 24, 2014]

qimqim




msg:4648546
 1:10 pm on Feb 24, 2014 (gmt 0)

The #1 is there! The copy was abit hasty!

qimqim




msg:4648550
 1:15 pm on Feb 24, 2014 (gmt 0)

Somrhting has gone wrong!

When I placed the code originally, I tested it and it worked, i.e. if you entered www.example.net in the url it opened prefectly as example.net.

I just tried it and it does not work. The www version brings uo a deformed page.

Please, see what has gone wrong.

qimqim




msg:4648554
 1:50 pm on Feb 24, 2014 (gmt 0)

Please, delete my last post

This is the updated file with small mistakes amended as per g1smd

The pages work again, so unless there is something really stupid I am goinf to keep them this way, But I would appreciate your comments.

# 1 Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php

# 2 Do not allow access to the directories
Options -Indexes

# 3
AddType text/x-component .htc

# 4 allow all except those indicated here
<Files *>
order allow,deny
allow from all

</Files>


# block visitors referred from indicated domains
RewriteEngine on
# For security reasons, Option followsymlinks cannot be overridden.

#5 Options +FollowSymlinks
Options +SymLinksIfOwnerMatch
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]



#6 redirect from www
RewriteCond %{HTTP_HOST} ^www.example\.net$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.net/$1 [R=301,L]



#7 redirects from file that changed name

Redirect 301 /Pinto/oldindex.html http://example.net/Pinto/oldindex.php
Redirect 301 /Asia/Indonesia/bali.html http://example.net/Asia/Indonesia/bali.php
Redirect 301 /Asia/Indonesia/indonesia.html http://example.net/Asia/Indonesia/indonesia.php


#8 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

g1smd




msg:4648563
 2:11 pm on Feb 24, 2014 (gmt 0)

You are posting and reposting code quicker than anyone can reply.

Use the edit button under your user name to remove the text of the post you no longer want.

The reason the code does not work is because you are choosing which parts to change rather than doing all and you have introduced typos as you are making changes.

Once you have changed everything as listed, renumber the rules 1 to 14 and we can proceed to getting it all working by fixing any remaining errors.

qimqim




msg:4648572
 2:25 pm on Feb 24, 2014 (gmt 0)

hi g1smd

I have to go slowly, I have an old brain...

Could you just help me understand one particular part of the file, which you told me to invert and I have now come to the conclusion that the second part is not doing what it is supposed to do anyway?

#6 redirect from www
RewriteCond %{HTTP_HOST} ^www.example\.net$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.net/$1 [R=301,L]


Now the first part tells the browser to load example.net when someone types www.example.net. And what is ^(.*)$ for?

the second part was supposed to do the same of somebody typed www.example.net/index.html
and I suppose I should also introduce another rule for example.net/index.html

These last two are supposed to get Google to look at all of them as one.

Now the second part of what I have does not do that, does it?

Would this make any sense?


RewriteCond %{HTTP_HOST} ^www.example\.net/index\.html$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]

g1smd




msg:4648574
 2:32 pm on Feb 24, 2014 (gmt 0)

HTTP_HOST can only match the hostname, therefore the RegEx pattern must not contain path or file info.

Rule 6a and 6b have missing escaping and both rules are non-optimum in multiple ways.

Each ruleset has a Condition and a Rule and each of those has a RegEx pattern.

Rule 6a - Condition pattern should be !^(example\.net)?$

Rule 6b - needs fixes to both patterns, Condition and Rule, adding missing escaping of literal pertiods and replacing .* with ([^/]+/)* in both places.

Rule 6b - Condition pattern should begin ^[A-Z]{3,9}\ followed by a space then a slash and then the remainder of pattern.

Rule 6b - should be before Rule 6a.

[edited by: g1smd at 3:09 pm (utc) on Feb 24, 2014]

qimqim




msg:4648575
 2:39 pm on Feb 24, 2014 (gmt 0)

Hi

I'm sorry but I am totally ignorant on htaccess Speak.

What is missing escaping?

You say that
Rule 6a - Condition pattern should be !^(example\.net)?$

but isn't "!" saying "if not example.net"
when what I want to say is "if www.example.net, then..."

Sorry, but it's too much for me!

Tell me is there any way the current code could be blocking Google from scanning my site? I put in a new sitemap 4 days ago with 168 pages and they only indexed 9 so far. Usually they go straight into 80/90 and then stop a couple of days later at 1207130

g1smd




msg:4648580
 2:45 pm on Feb 24, 2014 (gmt 0)

Yes, if user has requested "NOT example.net" then redirect to example.net
This redirects requests for www.example.net, www.example.net:80, example.net:80 etc.

Literal periods in RegEx patterns must be escaped as \.

Once you have changed everything as listed, renumber the rules as 1 to 14 and we can proceed to getting it all working by fixing any remaining errors.

qimqim




msg:4648586
 3:17 pm on Feb 24, 2014 (gmt 0)

Thanks

So, in English, what do the two sets below mean exactly. The first works well, the second I cannot really understand the syntax

RewriteCond %{HTTP_HOST} !^(example\.net)?$
[NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.net/$1 [R=301,L]

[edited by: qimqim at 3:28 pm (utc) on Feb 24, 2014]

aakk9999




msg:4648587
 3:20 pm on Feb 24, 2014 (gmt 0)

The second one says:

If the request contains index.html, redirect it to a folder in which index.html is placed.

So this is done to redirect www.example.net/somefolder/index.html to www.example.net/somefolder/ since both of these URLs would show the same content but the rule will not work as it is missing the GET/POST part of the request as per g1smd's post before (the ^[A-Z]{3,9}\ part).

[editReason]Corrected misinformation[/editReason]

[edited by: aakk9999 at 3:53 pm (utc) on Feb 24, 2014]

qimqim




msg:4648591
 3:31 pm on Feb 24, 2014 (gmt 0)

Hi
I've changed the other condition and, YES, it works...

Now, from what you tell me the second is not doing wht I thought it did. My understanding of Google ranking is that is they see example.com, www.example.com, www.example.com/index.html, etc they consider each a different site with identical content, and one of several things happen: they divide the credit among all of them, or ban them into outer space.

So, does the sond set do any of this?

PS - maybe it does. id there is only one index.html and it is in the root directory if Google finds it it will be redirected to the example.net. is that so?

aakk9999




msg:4648595
 3:37 pm on Feb 24, 2014 (gmt 0)

My understanding of Google ranking is that is they see example.com, www.example.com, www.example.com/index.html, etc they consider each a different site with identical content, and one of several things happen: they divide the credit among all of them, or ban them into outer space.

Yes, these are different URLs with identical content and Google *may* consider each credit separately.

However, I think that in this particular case Google pretty much recognises that this is the same page and combines the credit (as this is one of the most common canonicalisation problems and the easiest for machine to understand). What it may not do however is to attribute the credit to URL version you consider the "main" one.

And importantly, Google will not ban the site to outer space when they have this duplication. Duplicate content is not penalty per se, but it can damage site's ranking for a different reasons.

[edited by: aakk9999 at 3:39 pm (utc) on Feb 24, 2014]

qimqim




msg:4648596
 3:38 pm on Feb 24, 2014 (gmt 0)

Hi

You've been insisting in numbering 1 to 14 but do you mind if I leave the two last blocks together as it makes it easier for me to see aht they are?

# 1 Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php

# 2 Do not allow access to the directories
Options -Indexes

# 3
AddType text/x-component .htc

# 4 allow all except those indicated here
<Files *>
order allow,deny
allow from all

</Files>


# block visitors referred from indicated domains
RewriteEngine on
# For security reasons, Option followsymlinks cannot be overridden.

#5 Options +FollowSymlinks
Options +SymLinksIfOwnerMatch
RewriteCond %{HTTP_REFERER} semalt\.com [NC]
RewriteRule .* - [F]
RewriteCond %{HTTP_USER_AGENT} libwww-perl
RewriteRule .* – [F]



#6 redirect from www

RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.net/$1 [R=301,L]




#7 redirects from file that changed name

Redirect 301 /Pinto/oldindex.html http://example.net/Pinto/oldindex.php
Redirect 301 /Asia/Indonesia/bali.html http://example.net/Asia/Indonesia/bali.php
Redirect 301 /Asia/Indonesia/indonesia.html http://example.net/Asia/Indonesia/indonesia.php


#8 bandwidth theft
RewriteCond %{HTTP_REFERER} !^http://example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://example.net$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.net$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

qimqim




msg:4648597
 3:40 pm on Feb 24, 2014 (gmt 0)

Hi aakk9999

Thanks for the input, So, do you think the current code (once tidied up) is good enough for Google? I understand that thei preferred format is without the www which is why I am doing this

#6 redirect from www

RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]

RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.example.net/$1 [R=301,L]

g1smd




msg:4648599
 3:44 pm on Feb 24, 2014 (gmt 0)


As we are going backwards, I think it best that I withdraw from this thread.

qimqim




msg:4648600
 3:50 pm on Feb 24, 2014 (gmt 0)

I'm sorry g1smd. I appreciate the time you took with me, I'm never easy. The fact is that now I want to go slowly and only want to sort out the seond part of the current #6

i understand your position. I am sorry.

aakk9999




msg:4648601
 3:52 pm on Feb 24, 2014 (gmt 0)

My mistake, I have edited the post above to correct my misinformation so perhaps g1 will help now

qimqim




msg:4648604
 4:02 pm on Feb 24, 2014 (gmt 0)

Like this?

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html
RewriteRule ^(.*)index.html$ http://www.example.net/$1 [R=301,L]

But the Rule should be without the WWW

qimqim




msg:4648607
 4:12 pm on Feb 24, 2014 (gmt 0)

Success!

I typed www.example.net/index.html and the page opened as example.net

I wonder if Google sees it the same way.

Any minor adjustments to this code will be much appreciated...

#6 redirect from www
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html
RewriteRule ^(.*)index.html$ http://example.net/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^(example\.net)?$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [R=301]

This 113 message thread spans 4 pages: < < 113 ( 1 [2] 3 4 > >
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved