homepage Welcome to WebmasterWorld Guest from 54.234.60.133
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

This 36 message thread spans 2 pages: 36 ( [1] 2 > >     
Some people need the "http://" part to access my site!
virtuals




msg:1515348
 8:21 pm on Feb 20, 2006 (gmt 0)

Sounds wired but it is true!

From with ISPs when people put this in their address bar and press enter or go, nothing happens.

Mydomain.com

No error message; no page loading … nothing! It just freezes. In this case they can still access other sites with out typing the [www....] Part. I.e. they can access yahoo by just typing yahoo.com in address bar and pressing go.

In this case they can only access my site by adding the http part. like this:

http://www.mydomain.com

I couldn’t believe it my self until I tried accessing my newly reached site from a coffee net.

I have this in my .htaccess file. Am I missing something there?

RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www. ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.)¦.*)$ [OR,NC]
RewriteCond %{HTTP_HOST}/www. ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))$ [NC]
RewriteRule ^ http://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]

DirectoryIndex index.php index.shtml index.html index.htm

[I'm trying to remove index.php from my urls, also forcing non www requests to www one and adding trailing slash to all my urls]

Thank you

[edited by: jdMorgan at 12:36 am (utc) on Feb. 21, 2006]
[edit reason] De-linked [/edit]

 

jdMorgan




msg:1515349
 11:04 pm on Feb 20, 2006 (gmt 0)

1) What exactly is the following code supposed to do? It looks very, um, "non-optimal."

RewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www. ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.)¦.*)$ [OR,NC]
RewriteCond %{HTTP_HOST}/www. ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))$ [NC]
RewriteRule ^ http://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]

2) Are you sure there are no additional referrer-based rules in your code or in the server config?
3) What do you see in your server's access and error logs?

Jim

virtuals




msg:1515350
 11:32 pm on Feb 20, 2006 (gmt 0)

1) That is suppose to force non www requests to www ones and also add a trailing slash to all my urls if they do not already contain one.

2) yes , no more rules in my code nor in the server config.

3)I will check it and report it here ...

thank you

virtuals




msg:1515351
 11:48 pm on Feb 20, 2006 (gmt 0)

3) ok . No error logs available.

jdMorgan




msg:1515352
 2:10 am on Feb 21, 2006 (gmt 0)

Try this simpler-to-understand version:

RewriteEngine on
RewriteBase /
#
# Add trailing slash if missing (skip rewrite for paths with
# a period the last part, already ending in slash, or blank)
RewriteCond %{REQUEST_URI} !(\.[^/]+¦/)$
RewriteRule (.+) /$1/
#
# Redirect non-www domains to www domains w/same file
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http:www.%{HTTP_HOST}/$1 [R=301,L]
#
# If requested resource does not exist as a file or directory, rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1 [L]

Note that you must change the broken pipe "¦" character to a solid pipe character before use, and flush your browser cache after any change to your configuration file(s). Also, there is no [L] flag on the first rule because we do want rule processing to continue.

Jim

virtuals




msg:1515353
 9:37 pm on Mar 6, 2006 (gmt 0)

Are you sure this code works? I'm getting a 500 error

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

And yes I did change the broken pipe.

Thanx

virtuals




msg:1515354
 12:40 am on Mar 7, 2006 (gmt 0)

This is what i got in my error logs:

Invalid command 'index.php', perhaps mis-spelled or defined by a module not included in the server configuration

jdMorgan




msg:1515355
 1:41 am on Mar 7, 2006 (gmt 0)

That means that Apache is confused about the meaning of a line in your file that starts with "index.php"
You might want to check your line-wraps and comment symbols (#) to make sure that no line starts with "index.php"

I also noticed a couple of typos in the code I posted above. THis might work better:

RewriteEngine on
RewriteBase /
#
# Add trailing slash if missing (skip rewrite for paths with
# a period the last part, already ending in slash, or blank)
RewriteCond %{REQUEST_URI} !(\.[^/]+¦/)$
RewriteRule (.+) /$1/
#
# Redirect non-www domains to www domains w/same file
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http:[b]//ww[/b]w.%{HTTP_HOST}/$1 [R=301,L]
#
# If requested resource does not exist as a file or directory, rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) [b]/ind[/b]ex.php/$1 [L]

Jim

virtuals




msg:1515356
 2:24 am on Mar 7, 2006 (gmt 0)

Thanx

what is the deference between these 3:

1:
RewriteRule ^(.*)$ index.php/$1 [L]
2:
RewriteRule (.*) /index.php/$1 [L]
3:
RewriteRule (.*) index.php/$1 [L]

virtuals




msg:1515357
 2:29 am on Mar 7, 2006 (gmt 0)

Now i'm getting this error:

Bad Request
Your browser sent a request that this server could not understand.

=(

alcheme




msg:1515358
 7:40 am on Mar 8, 2006 (gmt 0)

Hi JP,

This does work:

RewriteEngine on
RewriteBase /
#
# Add trailing slash if missing (skip rewrite for paths with
# a period the last part, already ending in slash, or blank)
RewriteCond %{REQUEST_URI}!(\.[^/]+¦/)$
RewriteRule (.+) /$1/
#
# Redirect non-www domains to www domains w/same file
RewriteCond %{HTTP_HOST}!^www\.
RewriteRule (.*) [%{HTTP_HOST}...] [R=301,L]
#

HOWEVER, I am using OSCOMMERCE.

I can change it so the domain always starts with a [www....] but the links and images inside the shopping cart program still look like this:

[url.com...]

Note the www. missing from the graphics and links inside the pages.

Is there a way to rewrite the links and images links?

Shane

jdMorgan




msg:1515359
 4:17 pm on Mar 8, 2006 (gmt 0)

Other than going through the OSCommerce code to find out how it creates URLs, I don't know what to tell you.

If OSC uses a system variable to build URLs, you could look into changing that variable in your config file, thus effecting a system-wide change from non-www to www.

For example, if your ServerName is example.com and there is a ServerAlias for www.example.com, then reversing those two values in httpd.conf might fix the problem. See also USeCanonicalDomain -- although I'm not sure that setting would change anything realted to OSC.

Another alternative would be to use the non-www domain as your canonical domain name by reversing the non-www to www redirect posted above. This would require search engines to change all their listings from www to non-www, a process that would take 30 days or more, and it would also be a good idea to ask your major link sources to change them as well.

mod_rewrite works as requests are received at your server, before any content-handlers or scripts are invoked. Therefore, it cannot be used to change links that are published on your pages.

Jim

extras




msg:1515360
 5:01 pm on Mar 8, 2006 (gmt 0)

I wrote the code he initailly used, and it does conversion of non-www to www
and the redirect for URLs without trailing slash in one shot.

Normally, it goes like this:
http://example.com/subdir <== Input
http://example.com/subdir/ <== Redirect by Apache
http://www.example.com/subdir/ <== Redirect for adding www

With the code, it goes like this:
http://example.com/subdir <== Input
http://www.example.com/subdir/ <== Redirect for adding www and trailing slash

But the code must be placed after "SEO friendly/ShortURL' code, in general.
And it's not compatible with some sites that uses filename without extension.

Same thing for the Jim's code.
I mean, the trailing slash code should be placed after the OSc, Drupal, whatever using the rewriteRule, most probably.

RewriteEngine on
RewriteBase /
#
# If requested resource does not exist as a file or directory, rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php/$1 [L]
#
# Add trailing slash if missing (skip rewrite for paths with
# a period the last part, already ending in slash, or blank)
RewriteCond %{REQUEST_URI} !(\.[^/]+¦/)$
RewriteRule (.+) /$1/
#
# Redirect non-www domains to www domains w/same file
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) [%{HTTP_HOST}...] [R=301,L]

If you don't have access to error.log, you can use small cgi/php to check what you are getting.
env.cgi

#!/bin/sh
echo
printenv¦sort

Then add a RewriteRule for testing.
RewriteCond %{QUERY_STRING} ^zzz
RewriteRule !^/*env.cgi env.cgi [L]

Type "example.com/?zzz" in the browser, and you should see all env variables for you to study the situation.

If you prefer PHP: env.php
[php]
<pre><? print_r($_SERVER);?>
[/php]

RewriteCond %{QUERY_STRING} ^zzz
RewriteRule !^/*env.php env.php [L]

As it requires QUERY_STRING to be started with "zzz" (or any other string you prefer), normal requests are not affected unless your site uses parameter named "zzz".

virtuals




msg:1515361
 4:58 pm on Mar 19, 2006 (gmt 0)

Should the [L] part be there in the fist rule?

Thank you

virtuals




msg:1515362
 11:57 am on Mar 22, 2006 (gmt 0)

No one? :(

jdMorgan




msg:1515363
 2:48 pm on Mar 22, 2006 (gmt 0)

The answer depends on which code in which message you're asking about, and therefore, to whom your question is directed...

Jim

virtuals




msg:1515364
 4:11 pm on Mar 22, 2006 (gmt 0)

Sorry , jdMorgan, You are right.

I was talking about extras's last post.

RewriteEngine on
RewriteBase /
#
# If requested resource does not exist as a file or directory, rewrite to index.php
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule (.*) /index.php/$1 [L]
#
# Add trailing slash if missing (skip rewrite for paths with
# a period the last part, already ending in slash, or blank)
RewriteCond %{REQUEST_URI}!(\.[^/]+¦/)$
RewriteRule (.+) /$1/
#
# Redirect non-www domains to www domains w/same file
RewriteCond %{HTTP_HOST}!^www\.
RewriteRule (.*) [%{HTTP_HOST}...] [R=301,L]

Shoild the [L] be there in the first rule?

virtuals




msg:1515365
 11:24 am on Mar 23, 2006 (gmt 0)

Now that is more clear , would you please answere my question jdMorgan?

Thank you!

jdMorgan




msg:1515366
 2:55 pm on Mar 23, 2006 (gmt 0)

I would order the code as I showed in my last code-post above, so that trailing slashes are added if needed, then (no [L] flag) the domain is canonicalized and a redirect is done immediately if necessary ([R=301,L] flags), and finally, requests for non-existent files are internally rewritten to your PHP script.

If you do this script rewrite step before the domain canonicalization redirect and you don't use an [L] flag on it, then you will expose your script's URL to users and search engines, and it will get listed in search engines -- not good. If you do use an [L] flag, then the domain won't be canonicalized for requests handled by the script. So that code order is just not right.

Jim

virtuals




msg:1515367
 6:29 pm on Mar 23, 2006 (gmt 0)

Thanks for the clarification.

What prevented me from using your code was the error I received after your code.

Bad Request
Your browser sent a request that this server could not understand.

Would you please check it again?

Thank you

jdMorgan




msg:1515368
 8:03 pm on Mar 23, 2006 (gmt 0)

> Would you please check it again?

I can't tell what's wrong without seeing your server error log. Bad Request means that the browser sent a bad request to your server. It's possible that this was the result of a redirection loop, but it's hard to tell.

Maybe it's this line, missing two slashes:
RewriteRule (.*) http:www.%{HTTP_HOST}/$1 [R=301,L]
Should be:
RewriteRule (.*) [%{HTTP_HOST}...] [R=301,L]

And this important reminder, already posted above:
Note that you must change the broken pipe "¦" character to a solid pipe character before use.

Jim

virtuals




msg:1515369
 10:36 pm on Mar 23, 2006 (gmt 0)

Jim, with your code this is what happens:

http://example.com/a/b

http://www.example.com//a/b//b

It is odd, it should be just :

http://www.example.com/a/b/

jdMorgan




msg:1515370
 12:58 am on Mar 24, 2006 (gmt 0)

This code is in .htaccess, and not in httpd.conf, right?

Jim

virtuals




msg:1515371
 2:56 am on Mar 24, 2006 (gmt 0)

yes, it is in .htaccess file.

jdMorgan




msg:1515372
 1:34 am on Mar 26, 2006 (gmt 0)

Please post the current relevant code.

Jim

virtuals




msg:1515373
 10:42 am on Mar 26, 2006 (gmt 0)

Thank you Jim. this is what I use:

-------------------------------------

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI}!(\.[^/]+¦/)$
RewriteRule (.+) /$1/

RewriteCond %{HTTP_HOST}!^www\.
RewriteRule (.*) [%{HTTP_HOST}...] [R=301,L]

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule (.*) /index.php/$1 [L]

jdMorgan




msg:1515374
 2:15 pm on Mar 27, 2006 (gmt 0)

Well, I've looked at this several times now, and I don't see anything in there that would rewrite to
http://www.example.com//a/b//b instead of http://www.example.com/a/b/

I suspect that your serve is misconfigured, or that some other code in httpd.conf or another .htaccess file is interfering with the rewrites.

Jim

virtuals




msg:1515375
 2:23 pm on Mar 27, 2006 (gmt 0)

Thank you for your time, Then I will contact my hosting company.

virtuals




msg:1515376
 10:28 pm on Mar 27, 2006 (gmt 0)

Jim,
I did contact them and they said that there is quite a few errors in your syntax, and was not actually a server problem.

They gave me this instead but this is not adding the trailing slash to urls.
----------------------------
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI}!(.[^/]+¦/)$
RewriteRule (.+) /$1/

RewriteCond %{HTTP_HOST}!^www.
RewriteRule (.*) [%{HTTP_HOST}...] [R=301,L]

RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule (.*) index.php?$1 [L]
----------------------------

I will appreciate any comment.
Thank you

jdMorgan




msg:1515377
 11:08 pm on Mar 27, 2006 (gmt 0)

> they said that there is quite a few errors in your syntax, and was not actually a server problem.

How kind of them, since they only changed two characters, and one of their changes is incorrect... :)

This line has been changed, and will prevent the trailing slash fix from working:

RewriteCond %{REQUEST_URI} !(.[^/]+¦/)$

The other change was to remove the leading slash from index.php in the final rule, a change which indicates that your server root is not defined properly or that your .htaccess code is not in the Web root directory.

RewriteRule (.*) index.php?$1 [L]

Now since I made "quite a few errors in my syntax," it's probably best not to trust my code. But you might try:

RewriteEngine on
RewriteBase /
#
# Add trailing slash if trailing slash is not present and
# URI does not end with a period and filetype (e.g. .gif)
RewriteCond %{REQUEST_URI} [b]!(\.[/b][^/]+¦/)$
RewriteRule (.+) /$1/
#
# Redirect to canonical doamin if non-canonical domain is
# requested (prepend "www" to requested hostname)
RewriteCond %{HTTP_HOST} !^www.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
#
# If requested resource does not exist as a file or directory,
# rewrite to index.php with requested path as query parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?$1 [L]

Change all broken pipe "¦" characters to solid pipes before use; Posting on this forum mosifies pipe characters.

Jim

This 36 message thread spans 2 pages: 36 ( [1] 2 > >
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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved