Welcome to WebmasterWorld Guest from 54.162.139.105

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Setting up Extensionless URLs with htaccess in MAMP

getting error

     
6:17 pm on Oct 30, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


I started a similar thread back in Jan on the same subject but that website got put on hold. I'm now working on another website and recently started another thread on how to install and MAMP.
I'm using some of info from the original thread, plus what I learned from the installing Mamp thread.

I left the extensions on the file names.

All links are relative.

On the home page I took the extension off one page I'm using for a test. I left the slash off the end but also tested it with the slash on. when I mouse over it in the browser it shows up estensionless but it throws server not found error if I open the page.

I have MAMP installed and I can open pages of the website within Mamp. I also loaded htaccess so the includes would work (for header, etc).

The only other thing I have in htaccess is for extensionless urls (see below). I've tried several settings for the rewrite URL, as mentioned in previous threads, and so far nothing is working.

here is what is currently in htaccess:

(I understand I need to change example.com to the domain once I load it onto the web server)

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

ErrorDocument 404 /missing.htm
AddHandler server-parsed .htm
#
Options +Includes
Options +FollowSymLinks
RewriteEngine on
#
RewriteBase /
#RewriteBase /example.com/
# check for file not existing
RewriteCond %{REQUEST_FILENAME} !-f
# check for directory not existing
RewriteCond %{REQUEST_FILENAME} !-d
# check for filename not ending in .htm to avoid looping
RewriteCond %{REQUEST_FILENAME} !\.htm$
# if the above conditions are met of no matching file, dir or htm file
# then rewrite to a .htm file
RewriteRule ^(([^./]+/)*[^./])$ /$1.htm [L]

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

I get ERROR MESSAGE: Server not found

It was suggested in the earlier thread that I should use Live http headers in Firefox. Here is the last input from trying to access the page.

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

[ajax.googleapis.com...]

GET /ajax/libs/jquery/1.6.2/jquery.min.js HTTP/1.1
Host: ajax.googleapis.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
If-Modified-Since: Mon, 02 Apr 2012 18:24:28 GMT
Cache-Control: max-age=0

HTTP/1.1 304 Not Modified
Date: Thu, 30 Oct 2014 07:51:32 GMT
Expires: Fri, 30 Oct 2015 07:51:32 GMT
Age: 37970
Server: GFE/2.0
Alternate-Protocol: 80:quic,p=0.01

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

Can anyone see what might be wrong?
6:50 pm on Oct 30, 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


Cache-Control: max-age=0
The 304 response indicates that the header includes an 'if modified since' setting and it shows a cache control with a max-age=0 so nothing gets returned.

I don't see what that has to do with a server not found error message though. If you try on a different browser do you get the same error? I ask in case you have caching disabled for dev work.
7:57 pm on Oct 30, 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:14245
votes: 550


#RewriteBase /example.com/

? That would result in rewriting to the content of
www.example.com/example.com/rest-of-rewrite-target
A RewriteBase is only used in rewrites (no [R] flag) and then only when the target as written doesn't already begin in / slash. So you basically haha don't need the RewriteBase line at all.

The LiveHeaders quoted part doesn't say anything about "server not found".
:: quick detour to check ::
### FF has jumped on the execrable "interpret everything as a search query" bandwagon (though why this should lead to a page in our very own /foo/ subforum is more than I can understand). Finally got it to work by requesting "example.local". LiveHeaders doesn't say anything if it can't find the server-- it only shows request/response headers when a server is found-- so that's a red herring.

Do you now get your custom 404 page? You talked about this in one of the other threads but I don't think we pursued the subject. If includes are working, then we'll assume htaccess is recognized.
:: further detour ::
Nope, I'm wrong, MAMP sets "Options All" on the directory containing your site files, so includes would happen anyway.

Have we established conclusively that your local htaccess file is recognized? Throw in something like
RewriteRule foobar /widget.html [R=301,L]

and verify that (a) you get your custom 404 page and (b) the browser's address bar says something like
http:/ /localhost/widget.html
9:45 pm on Oct 30, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


Yes, my local htaccss is working because the includes are working.

I have my own custom 404 page but that is not what loaded.

My browsers address bar say the following whether I open the home page from the client file or from within applications/mamp/client

file:///Applications/MAMP/htdocs/EXAMPLE.com/index.htm

If I load the welcome page and open the home page from there it says:

http://localhost/EXAMPLE.com/index.htm

Should I open the page from the later or does it matter. Either way that one link still trows a server not found message.

I added the line you requested.

I haven't used live headers before so I may not be doing it right. I'm clearing the cache before trying again so the page doesn't get too long.

@not2easy I haven't done anything with cache control in conf. if that's what you mean. I haven't edited anything in there.

here is the http header: (I might have doubled it as it didn't record anything the first time or else it takes a long time to load the report).

To clarify -- I clear the cache on live headers, refresh the home page and try the link and save whats in the http header.

http://localhost/example.com/index.htm

GET /example.com/index.htm HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/example.com/
Cookie: SQLiteManager_currentLangue=2
Connection: keep-alive
Cache-Control: max-age=0

HTTP/1.1 200 OK
Date: Thu, 30 Oct 2014 21:54:54 GMT
Server: Apache/2.2.29 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.8 PHP/5.6.2 mod_ssl/2.2.29 OpenSSL/0.9.8za DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Accept-Ranges: bytes
Content-Length: 5854
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
----------------------------------------------------------
http://localhost/example.com/aatisbk.css

GET /example.com/aatisbk.css HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: text/css,*/*;q=0.1
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/example.com/index.htm
Cookie: SQLiteManager_currentLangue=2
Connection: keep-alive
If-Modified-Since: Tue, 28 Oct 2014 16:36:17 GMT
If-None-Match: "61121f4b-20cd-5067e3f0cc240"
Cache-Control: max-age=0

HTTP/1.1 304 Not Modified
Date: Thu, 30 Oct 2014 21:54:54 GMT
Server: Apache/2.2.29 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.8 PHP/5.6.2 mod_ssl/2.2.29 OpenSSL/0.9.8za DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Connection: Keep-Alive
Keep-Alive: timeout=5, max=99
Etag: "61121f4b-20cd-5067e3f0cc240"
----------------------------------------------------------
http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js

GET /ajax/libs/jquery/1.6.2/jquery.min.js HTTP/1.1
Host: ajax.googleapis.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/example.com/index.htm
Connection: keep-alive
If-Modified-Since: Mon, 02 Apr 2012 18:24:28 GMT
Cache-Control: max-age=0

HTTP/1.1 304 Not Modified
Date: Thu, 30 Oct 2014 07:51:32 GMT
Expires: Fri, 30 Oct 2015 07:51:32 GMT
Age: 50603
Server: GFE/2.0
Alternate-Protocol: 80:quic,p=0.01
----------------------------------------------------------
http://localhost/example.com/images/tis-books-logo.gif

GET /example.com/images/example-logo.gif HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/example.com/index.htm
Cookie: SQLiteManager_currentLangue=2
Connection: keep-alive
If-Modified-Since: Mon, 11 Aug 2014 18:21:40 GMT
If-None-Match: "61121ef2-1227-5005ea04ed500"
Cache-Control: max-age=0

HTTP/1.1 304 Not Modified
Date: Thu, 30 Oct 2014 21:54:54 GMT
Server: Apache/2.2.29 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.8 PHP/5.6.2 mod_ssl/2.2.29 OpenSSL/0.9.8za DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Connection: Keep-Alive
Keep-Alive: timeout=5, max=98
Etag: "61121ef2-1227-5005ea04ed500"
----------------------------------------------------------
http://localhost/example.com/images/intro-example.jpg

GET /example.com/images/intro-example.jpg HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/example.com/index.htm
Cookie: SQLiteManager_currentLangue=2
Connection: keep-alive
If-Modified-Since: Mon, 11 Aug 2014 19:38:35 GMT
If-None-Match: "61122515-9183-5005fb36224c0"
Cache-Control: max-age=0

HTTP/1.1 304 Not Modified
Date: Thu, 30 Oct 2014 21:54:54 GMT
Server: Apache/2.2.29 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.8 PHP/5.6.2 mod_ssl/2.2.29 OpenSSL/0.9.8za DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
Etag: "61122515-9183-5005fb36224c0"
----------------------------------------------------------
http://localhost/example.com/images/ibpa.jpg

GET /example.com/images/ibpa.jpg HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/example.com/index.htm
Cookie: SQLiteManager_currentLangue=2
Connection: keep-alive
If-Modified-Since: Tue, 21 Oct 2014 18:18:57 GMT
If-None-Match: "611c5731-1114-505f2dd534640"
Cache-Control: max-age=0

HTTP/1.1 304 Not Modified
Date: Thu, 30 Oct 2014 21:54:54 GMT
Server: Apache/2.2.29 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.8 PHP/5.6.2 mod_ssl/2.2.29 OpenSSL/0.9.8za DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Connection: Keep-Alive
Keep-Alive: timeout=5, max=97
Etag: "611c5731-1114-505f2dd534640"
----------------------------------------------------------
http://localhost/example.com/images/apss.jpg

GET /example.com/images/apss.jpg HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:33.0) Gecko/20100101 Firefox/33.0
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/example.com/index.htm
Cookie: SQLiteManager_currentLangue=2
Connection: keep-alive
If-Modified-Since: Tue, 21 Oct 2014 18:18:33 GMT
If-None-Match: "611c572b-42b6-505f2dbe51040"
Cache-Control: max-age=0

HTTP/1.1 304 Not Modified
Date: Thu, 30 Oct 2014 21:54:54 GMT
Server: Apache/2.2.29 (Unix) mod_fastcgi/2.4.6 mod_wsgi/3.4 Python/2.7.8 PHP/5.6.2 mod_ssl/2.2.29 OpenSSL/0.9.8za DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
Etag: "611c572b-42b6-505f2dbe51040"
----------------------------------------------------------

[edited by: phranque at 11:24 pm (utc) on Oct 30, 2014]
[edit reason] unlinked URLs [/edit]

11:20 pm on Oct 30, 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:14245
votes: 550


Yes, my local htaccss is working because the includes are working.

The conclusion doesn't follow from the premises. Includes will work so long as the Includes option is set-- and it looks as if MAMP does this by default (Options All, assuming 2.2). See what happens if you change something really obvious like the Indexes option and then request a directory that doesn't contain an index page.

I have my own custom 404 page but that is not what loaded.

Go back and look at the other thread. We need to figure out why it isn't displaying, and there are at least three possible reasons, none of them mutually exclusive.

My browsers address bar say the following whether I open the home page from the client file or from within applications/mamp/client
file:///Applications/MAMP/htdocs/EXAMPLE.com/index.htm

Anything beginning in "file://" is what you see when you open any html file directly from the desktop or from within a browser. It needs to start in http and then say /localhost/ possibly with a port number. Once you've got this version to load up, bookmark it so you don't need to keep typing in "localhost".

http://localhost/EXAMPLE.com/index.htm

Uh-oh, I think you've got your MAMP set to point to the wrong directory. It shouldn't say example.com; it should just say localhost/index.htm because the MAMP pseudo-server is taking the place of your "real" domain. In addition, it should never say /index.htm, because surely you've got an index redirect?

MAMP itself is set for the default .html and .php only, so if your index files are called index.htm you need to say so explicitly. This detail may not be in your htaccess, because if your real site is on shared hosting they've almost certainly added "index.htm" to the list already.

Edit: All those LiveHeaders quotations show that your browser is successfully finding the server (here "localhost").
I added the line you requested.

And then what happens if you request a filel whose name contains "foobar"? This line is just a simple test to verify that your htaccess is working as intended. It has no other purpose and can be deleted as soon as you've checked.

[edited by: lucy24 at 11:24 pm (utc) on Oct 30, 2014]

11:23 pm on Oct 30, 2014 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11071
votes: 106


your anchor elements are referring to urls that don't specify the protocol so starting the url with the hostname actually makes it look like a page-relative url.
since you are running locally, the homepage is probably http://localhost/

in other words, you should use href="http://example.com/index.htm" instead of href="example.com/index.htm".

actually you should link to http://example.com/ and specify index.htm as the default directory index document, but that's a separate issue.
11:27 pm on Oct 30, 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:14245
votes: 550


Oops, phranque, we overlapped
you should use href="http://example.com/index.htm"

If MAMP is set up correctly, you can use links with leading / and they will work exactly the same as on a "live" site. That's half the benefit of using a pseudo-server in the first place. (Without the server, links in leading / will take you to the top level of your Mac's HD-- almost certainly not where you want to be! Don't know if it's the same on other platforms.)

What worries me about "index.htm" is that the redirect isn't taking place-- whether or not the links themselves are correct-- though you have to assume a redirect exists.
12:38 am on Oct 31, 2014 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11071
votes: 106


or you could specify a protocol-relative url:
href="//example.com/index.htm"
12:51 am on Oct 31, 2014 (gmt 0)

Administrator

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

joined:Aug 10, 2004
posts:11071
votes: 106


Uh-oh, I think you've got your MAMP set to point to the wrong directory. It shouldn't say example.com; it should just say localhost/index.htm because the MAMP pseudo-server is taking the place of your "real" domain.

the urls used in your document depend on your content management system.
whether you use a fully specified url referring to the local server or the live server or a protocol-relative url or a root-relative url depends on your CMS configuration/content editing capabilities and your testing and configuration management requirements.
in other words, there's no "right" answer here - it depends...


In addition, it should never say /index.htm, because surely you've got an index redirect?

this. in coordination with the above-mentioned default directory index document configuration.
6:21 pm on Oct 31, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


Includes didn't work until I got the htaccess file loaded.

I am not using a CMS. I write my own html.

I don't have the redirect to get rid of index.htm set up yet, if that's what you mean. I posted the whole htaccess file earlier. Do I need to include it for MAMP to work?



Uh-oh, I think you've got your MAMP set to point to the wrong directory.


I don't think I set anything to point to any particular directory. the only changes I made were changing the ports to 80;7888;3306. I haven't made any changes in Conf.
The doc root is set as Mac HD/Apps/MAMP/htdocs
inside the example.com directory is a file I didn't add called "parent directory". when I click on it it takes me back to example.com and the location bar says localhost/example.com regardless. Is that supposed to be there?




I have the whole client data in a folder called example.com (not real name) so localhost.index.htm doesn't seem appropriate. Shouldn't it say localhost.example.com/index.htm?

Should I have not put all client files in a folder? If so, I assume that means I can only use one site in MAMP. I seem to recall I could use several without having to pay for the Pro version.

I changed all the file names for every page in the menu so there is a leading / on the relative file name. Now it throws a 404 error (url not found on this server) instead of the other error.

Then I realized I had index.htm on home page links in menu so changed it to "/" and tried again with the same 404.

@Lucy I found your instructions you posted on the other thread for the conf file. I saved a copy per your instructions and searched but there is no text called SubEthaEdit in that file. I can see the items you mentioned however.

It would sure help if there were instructions on how to use MAMP on the MAMP site. It takes 100 sec for the webstart page to open which is annoying.
8:27 pm on Oct 31, 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:14245
votes: 550


I posted the whole htaccess file earlier. Do I need to include it for MAMP to work?

You do not have to use an htaccess file with MAMP. But any rules have to be somewhere: either in an .htaccess file located where MAMP can see it (normally this would be in the root, side by side with index.htm, exactly as on your live site), or in the config file itself.

Shouldn't it say localhost.example.com/index.htm?

No, that would be a subdomain of example.com. /localhost/ alone means your own computer. MAMP's pseudo-server takes this as your domain root, so
MAMP localhost/index.html
=
"live" example.com/index.html
The physical arrangement of the pages on your hard drive should be exactly the same as on your live site.

Say the directory that contains your front page is
/blah/otherblah/filepath/
with these files

/blah/otherblah/filepath/index.html
/blah/otherblah/filepath/.htaccess
/blah/otherblah/filepath/pagename.html
/blah/otherblah/filepath/directory/index.html
/blah/otherblah/filepath/directory/pagename.html
/blah/otherblah/filepath/otherdir/index.html
/blah/otherblah/filepath/otherdir/pagename.html

Once you are on any page on your site within MAMP, following links will take you to
/localhost/index.html
/localhost/pagename.html
/localhost/directory/index.html
/localhost/directory/pagename.html
/localhost/otherdir/index.html
/localhost/otherdir/pagename.html

which in turn will be identical to what you see in your "live" site as
http://example.com/index.html
http://example.com/pagename.html
http://example.com/directory/index.html
http://example.com/directory/pagename.html
http://example.com/otherdir/index.html
http://example.com/otherdir/pagename.html

... except, of course, that it won't really say "index.html" because those will be redirected to /directory/ with slash alone.

It takes 100 sec for the webstart page to open which is annoying.

Something's wrong, then. Do you mean 100 sec when you click "Open start page" from the main MAMP window? Or 100 sec to start/stop the servers? That shouldn't take more than a few seconds*.

there is no text called SubEthaEdit in that file

There wouldn't be ;) That's the name of the text editor I use. You probably use a different one. I like SEE because you can change both encodings and line endings on the fly. It was originally developed for interactive work with other people who might be on a different platform; it's also good for historical stuff like ancient files that were saved in Mac-Roman encoding. As a supplement I use TextWrangler for multi-file searches.

Edit:
I don't think I set anything to point to any particular directory.

You may have stayed with the default. In the MAMP prefs, under Apache, there's a place where it asks for "Document Root". By default it's a directory inside the overall MAMP directory. But I find it much more convenient to point to a place elsewhere on the HD where I already have all the site files.


* In my case, exactly long enough for me to scream "Yawp! Why isn't it starting?" ... before it does start.
11:14 pm on Oct 31, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


My question was worded wrong:

I don't have the redirect to get rid of index.htm set up yet, if that's what you mean. I posted the whole htaccess file earlier. Do I need to include it for MAMP to work?


I was talking about "a redirect to get rid of index.htm", not the htaccess file.

I'm still confused about putting the clients data within a folder labeled "example.com" in the htdocs folder. It doesn't sound like that's the way it should be done.

Like I said earlier: "The doc root is set as Mac HD/Apps/MAMP/htdocs " and that is where I'm working from.

the doc files and htaccess are all at one level. No folders.

I don't want to use conf if htaccess will work without it.

Like I said, it takes 100sec to open the webstart page from the Mamp window. Not mamp servers.
11:22 pm on Oct 31, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


@ phranque yes my home page is "localhost"

However i have the whole site in a folder in htdocs called "example.com". So I click on that and then the link to index page then becomes "localhost/example/index.htm. I think that is the problem.

Also are you saying I should not be using relative urls in menu/nav links?
12:30 am on Nov 1, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


I went ahead and dumped everything that was in the htdocs file and reloaded the site files without being in a folder. I also loaded the htaccess file I've been using.

When I navigate to that page with my browser, the location bar now says:

localhost

However, the first thing on the page is " Index of / "
then lists the files below. If I click on the index.htm link I get a page of gobbledegook.
2:22 am on Nov 1, 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:14245
votes: 550


When I navigate to that page with my browser, the location bar now says:

localhost

However, the first thing on the page is " Index of / "
then lists the files below. If I click on the index.htm link I get a page of gobbledegook.

Uh-oh, something's wrong. Are you talking about an OS index or an Apache index? What does your browser's address bar say when you see this content? The whole thing, not just the word "localhost". In many newer browsers, you may have to copy-and-paste the contents of the address bar into some other document, because they obfuscate part of the address.

"Index of blahblah" is what your Mac shows you if you open a local file in your browser and then follow a link to anything that ends in a / directory slash. An Apache index is also called "Index of something-or-other" but it's differently formatted; you should be able to tell at a glance which one you're looking at. (On my system, the OS-generated index has lines of alternating background colors, and there's a "Show hidden files" option near the top.)

But "a page of gobbledegook" is extremely worrying, because at this point your browser should come back to life and render the html, regardless of who generated the index file for the directory. Do you mean bona fide gobbledegook, as in reams of nonsense? Or do you simply mean that your text is there but it doesn't look right? If your browser can't find your stylesheet, things will look pretty horrific.

I also don't understand how you can be getting an "index of..." screen when you're navigating to a page. Unless:

-- you navigate to a page called index.htm
-- there's an index redirect in place, either in htaccess or config, so the browser is redirected to / directory
-- the DirectoryIndex directive does not name "index.htm" (with that exact extension), so the browser shows you either the computer's index or the server's index.

This is truly the only explanation I can come up with. Still mystified about the gobbledegook, though, because the above explanation would preclude you ever getting to the "index.htm" page itself.
4:31 pm on Nov 1, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


I figured out that somehow the browser was picking up the index file I had put in the trash causing the gobbledegook (mass of non-code).

I emptied the cache and reloaded the index and htaccess file so now the gobbledegook is gone.

I am accessing the website with this url in the browser: [localhost...]

all file names have a slash in front and .htm on the end except the one page I was testing which has no .htm on the end.

All pages are loading correctly now except the one I was using for testing. It is throwing a 404 via the 404 page I set up so that is working now.

All pages that are fully loaded have the .htm extension on them however.
7:55 pm on Nov 1, 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:14245
votes: 550


http://localhost/index.htm

Good. That's what it should be saying. And once you get the index redirect working, it will say only
http://localhost/


It is throwing a 404 via the 404 page I set up so that is working now.

Double-check: You mean it's getting a 404 response, but it's showing your custom 404 page? Woo hoo, now we're getting somewhere.

Where is your ErrorDocument directive located? In htaccess? Next step is to confirm that your htaccess file is being recognized. (That's why I suggested-- either here or in one of the other threads-- the nonsense-name redirect. Files don't have to exist; it's just to make sure the redirect takes place.)

:: detour to httpd.conf in MAMP ::

MAMP itself does not contain any default ErrorDocument statements. If you search for "ErrorDocument" you'll get several hits, but those are just comment lines illustrating the different possible formats. Same thing you see in Apache docs. So if your custom 404 page is showing up, it can only be because an ErrorDocument directive in htaccess is being read.

Does "fully loaded" mean stylesheets, images, includes and everything?

Incidentally, what's the exact wording of your Include statements? These are SSIs, right? What type of link? I think the options are "Include" (relative link) or "Include Virtual" (site-absolute link with leading slash).
3:28 pm on Nov 2, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


Hi Lucy,

Yes, all the includes are loading, stylesheets, images, includes. This is a RWD site and even the dropdown menu appears if I shrink the page. Here is the url for includes:
<!--#include file="logo.txt" -->
I use virtual when pages are within folders but this site doesn't have any pages in folders (only about 10 pages and not likely to grow much bigger).

Yes, my custom 404 page is showing with my own unique text on it "... click one of the links in the menu). The custom 404 is located in the root (all pages are in the root). The ErrorDocument directive is at the very top my my htaccess file.

I'm not sure which index redirect you're talking about. Is it this one?

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

I tired it but that redirects to the live site so that is working. I commented it out.

Regardless, this means the htaccess file is working.

The only thing not working is extensionless URLs.
8:55 pm on Nov 2, 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:14245
votes: 550


I tried it but that redirects to the live site so that is working. I commented it out.

You may remember I said in one of the other threads that you need to change certain things in your MAMP site's htaccess. Normally any redirect should include the full protocol-plus-domain name. But within MAMP, you can't do this because you need to stay on MAMP. Sure, you could replace all occurrences of "www.example.com" with "localhost" but that's pretty silly. Just give everything a leading slash, removing the protocol-plus-domain but keeping the [R=301] flag. Since nobody but you will ever use the MAMP site, you do not have to worry about people typing in the wrong form of the domain name, and that's the only reason for the long version of the target.

Now that we've established that everything is working nicely, the extensionless rule should be a piece of cake. What have you tried so far? The rule will look identical in MAMP and on the live site: target beginning in / slash, and [L] flag alone. Put the rule after any existing rules that involve external redirects, such as the index.htm redirect.

Oh, and make sure you've added this line near the top of your htaccess:

DirectoryIndex index.htm


Your live site may not have this rule, because the host says something similar in the config file. But the .htm extension is not an Apache default, so you'll have to add it. Note that ".htm" and ".html" are different extensions and have to be listed separately. Your index redirect can cover both options by saying

index\.htm


without closing anchor-- but DirectoryIndex doesn't work that way.

Finally: Since you're using hand-rolled html (yay!) your index redirect does not need a condition. Instead, add one more flag
[R=301,L,NS]

"NS" means "no subrequests" which in turn means "do not invoke this rule if the request for 'index.htm' originated with mod_dir". The [NS] flag basically applies to any request created by internal server activity. It does not apply to requests created within mod_rewrite, such as extensionless-URL rewrites. For that you do need a %{THE_REQUEST} condition.

Has the extensionless page ever existed in .html form? If so, you will also need a redirect for people requesting the old form of the name. That's where the Condition kicks in. If it's a brand-new page that never had the .html extension in the first place, you can probably dispense with the redirect. I stress: probably. I don't know whether search engines routinely ask for .html versions of extensionless URLs, though it seems like the kind of thing they would do. (Same principle as asking for three forms of any directory name.)
3:37 pm on Nov 3, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


Hi Lucy24

The extensionless rule I'm using is what I got off an earlier thread.

I added DirectoryIndex and added NS to the index redirect and took the domain out .

The site has never been written in html. It went from htm to Wordpress with extensiionless urls.

Following is my new and improved Htaccess however it's now giving me an internal server error (using localhost in browser) so something is wrong. I commented out part of the index redirect for when the site goes live so it's easy to switch back and forth.

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

ErrorDocument 404 /missing.htm
AddHandler server-parsed .htm
DirectoryIndex index.htm
#
Options +Includes
Options +FollowSymLinks
RewriteEngine on
#
# Index Redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.htm\ HTTP/
# For Live site use following with domain included
#RewriteRule ^(([^/]+/)*)index\.htm$ http://www.example.com/$1 [R=301,L]
# For MAMP use following with domain removed:
RewriteRule ^(([^/]+/)*)index\.htm$ /$1 [R=301,L, NS]
#
# Extensionless rule - goes after all external redirects
# check for file not existing
RewriteCond %{REQUEST_FILENAME} !-f
# check for directory not existing
RewriteCond %{REQUEST_FILENAME} !-d
# check for filename not ending in .htm to avoid looping
RewriteCond %{REQUEST_FILENAME} !\.htm$
# if the above conditions are met of no matching file, dir or htm file
# then rewrite to a .htm file
RewriteRule ^(([^./]+/)*[^./])$ /$1.htm [L]
#
5:07 pm on Nov 3, 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:14245
votes: 550


The site has never been written in html. It went from htm to Wordpress with extensionless urls.

Say what now? I thought you'd been saying all along that everything is hand-rolled HTML. If it's WordPress, where's their own htaccess?

The part about "never in html" vs. "htm" makes me distinctly uneasy. It sounds like some confusion between the actual content of a physical file vs. spelling of the extension name, two almost wholly unrelated things.

How big is the site? The !-f and !-d tests are resource-intensive and should only be used as a last resort. And the %{REQUEST_FILENAME} condition is superfluous in any case, because the rule explicitly says "no periods in the filename".

^(([^./]+/)*[^./])

This looks as if two different RegExes have gotten mixed up. Use one or the other of:
^(([^/]+/)*([^/]+[^./])?)$
^([^.]+[^./])$
where the second form can be used if your URLs (whole path, not just the filename) never contain literal periods.

If you've constrained the rule so it only matches extensionless filenames, the !-f condition becomes superfluous, because you already know that the file doesn't exist. You only need a !-d test if the site actually has subdirectories, and then it's better to hand-code a rule listing the directories by name.
10:19 pm on Nov 3, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


I said I write HTML by hand (meaning also HTM) but not PHP.

I started out this website as htm, someone else took it over, put it into WP with extensionless .php urls now I've taken it out of WP and trying to keep the extensionless urls (I don't write php).

the site only has about 10 pages and not likely to get much bigger. All pages are in the root. the only sub directory is for images.

Here is the current WP htaccess for extensionless urls on the live site.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Should I change it to:

RewriteEngine On
RewriteRule ^index\.htm$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.htm [L, NS]
10:47 pm on Nov 3, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


I took the htaccess back to where the pages were loading before, commenting out the index redirect and except for adding the:
DirectoryIndex index.htm

The url I was testing without the .htm is now showing up as an extensionless url so I took .htm off all the other menu links and all the pages are fully loading and showing up without the .htm extension.

So I assume this means I just need to get the index redirect fixed.

Here is the current htaccess:

ErrorDocument 404 /missing.htm
AddHandler server-parsed .htm
DirectoryIndex index.htm
#
Options +Includes
Options +FollowSymLinks
RewriteEngine on
#
# Index Redirect
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.htm\ HTTP/
# For Live site use following with domain included
#RewriteRule ^(([^/]+/)*)index\.htm$ http://www.example.com/$1 [R=301,L, NS]
# For MAMP use following with domain removed:
#RewriteRule ^(([^/]+/)*)index\.htm$ /$1 [R=301,L, NS]
#
# Extensionless rule - goes after all external redirects
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.htm$
RewriteRule ^([^.]+[^./])$ /$1.htm [L]
#
12:09 am on Nov 4, 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:14245
votes: 550


The url I was testing without the .htm is now showing up as an extensionless url so I took .htm off all the other menu links and all the pages are fully loading and showing up without the .htm extension.

Hurrah!

Comment-out this line if you absolutely have to keep the WP section at all:
RewriteCond %{REQUEST_FILENAME} !-d 

Since everything is in the root, with no subdirectories, there's no need to force the server to do a directory check (a potential problem with extensionless URLs, because WP may interfere with mod_dir's job). This applies to all occurrences of the Condition, wherever it appears.

the only sub directory is for images.

That's fine. The rules as written will apply only to page requests, especially now that everything is extensionless.

As previously noted, the line
RewriteCond %{REQUEST_FILENAME} !\.htm$

is unnecessary, because the body of the rule has already specified that the requested filename cannot end in .htm (or any other extension).

If you're changing the URLs of existing pages, remember that you also have to redirect from old .htm to new extensionless. If the URLs have never existed in with-htm form, the redirect is probably not necessary, but do check logs periodically.
2:57 am on Nov 4, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


I made the changes mentioned above (WP will not be on the site once this goes live).

I am changing the URLS of existing pages but needed to get this working first. I already have those redirects set up. As I said, the site was originally in .htm.

I tried adding the index redirect back on and got the internal server error again.

Ever since you said to take the domain out of the last line it has been doing this. Did I write that line correctly?

ErrorDocument 404 /missing.htm
AddHandler server-parsed .htm
DirectoryIndex index.htm
#
Options +Includes
Options +FollowSymLinks
RewriteEngine on
#
# Index Redirect
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.htm\ HTTP/
# For Live site use following with domain included
#RewriteRule ^(([^/]+/)*)index\.htm$ http://www.example.com/$1 [R=301,L, NS]
#For MAMP use following with domain removed:
RewriteRule ^(([^/]+/)*)index\.htm$ /$1 [R=301,L, NS]
#
# Extensionless rule - goes after all external redirects
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+[^./])$ /$1.htm [L]
#
8:53 pm on Nov 6, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


I know the Index redirect works on live sites so I'm going to ignore trying to get it working on MAMP. Extensionless urls are working so I'm moving ahead and loaded the site on a temp folder on the server (no index turned on).

As a review - I have redesiged a site that is currently in WP that already has extensionless urls. I have changed it to a static site with htm with extensionless urls. Everything is working except I need to put a slash on the end because that is how Wordpress was set up.

Here is the wordpress redirect:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Here is what I have set up that is working in MAMP and on the live site except there are no slashes on the end of the filenames (I decided I do need directories listed as I have a directory full of pdf files).

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+[^./])$ /$1.htm [L]
#


My question is -- why are the two directives for WP and a static website so different and what do I need to do to add a slash on the end of each file name? Isn't the above directive supposed to add a slash?

Or should I have the slash on the links to files? Currently I don't.
9:18 pm on Nov 6, 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:14245
votes: 550


Isn't the above directive supposed to add a slash?

Nothing quoted in either of the two most recent posts adds a / slash. I see only the .htm rewrite. The slash-adding rule in its simplest form says

RewriteCond %{REQUEST_URI} !^/(images|stylesheets)
RewriteRule ^([^.]+[./])$ http://www.example.com/$1/ [R=301,L]

I made up the Condition; actual wording will depend on what's in the site. The idea is to exclude requests for real, physical directories, because search engines will ask for these in slashless form, and then you want mod_dir to be able to do its job. Alternately, you could explicitly code a preceding redirect that says-- without conditions--
RewriteRule ^(images|stylesheets)$ http://www.example.com/$1/ [R=301,L]

although frankly you might as well code a 403 right away, since that's what the request will end up getting. (We're talking here about directories that physically exist, but have no index page, whether hard-coded or auto-generated.)

But wait! If you decide you're using URLs in final-slash form, then all your htm rewrites also have to change so they now say
RewriteRule ^([^.]+)/$ /$1.htm [L]

See the difference? Instead of ending in
[^./])$
the rule instead has to end in
)/$
so the final / is (a) required rather than prohibited, and (b) omitted from the capture. Again, you have to exclude any directories that physically exist, because obviously you do not want to rewrite to
/images.htm

if /images/ is a real, physical directory. It's much more efficient to list exceptions by name instead of doing a !-d lookup.

And, finally, make sure any redirects from the old with-htm URLs point directly to the form you end up choosing, whether with or without final / slash.
10:31 pm on Nov 6, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3



I was wondering why the WP htaccess doesn't use a rule to add a slash so I checked the live site and it has a slash on the end of each link.

I assume this something set up within WP itself because the host said to set up a temp directory to work on the site and comment out the rules in WP htaccess rules because they are not needed when using WP as it has it's rules within the program.

As a test I tried just adding slashes on the end of each link (hoping to not have to make more changes to htaccess) but it's redirecting to the live site.

So I'll give it a try.

Thanks for your patience Lucy. I have a long list of character definitions for htaccess but I don't understand them all yet.
10:39 pm on Nov 6, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:June 4, 2002
posts: 1830
votes: 3


Opps. I just realized I can't make that change because the site itself is currently in a temporary folder so filling in example.com won't work.

Will it cause duplication issues if WP has a slash and the "new and improved site" doesn't? If so I can leave the slash off until the site goes live then deal with it.
6:22 am on Nov 7, 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:14245
votes: 550


I assume this something set up within WP itself

Yes, that's what makes WP-- or any CMS-- so inefficient. Things that could be done with a single Apache line are instead shunted off to multiple database calls and php routines.

Internal links-- ones from one page to another page on the same site-- should not include the protocol-plus-domain anyway. In WP there is probably a simple setting to change everything at once. When you make hard-coded html pages you can globally delete all occurrences of
http://www.example.com
(without the final slash, because you'll need to keep that) on all pages. Since you've only got 10 pages or so, go ahead and do it page by page. If there were lots of pages involved, you would want to use a text editor such as TextWrangler that can perform multi-file actions.
This 38 message thread spans 2 pages: 38