Welcome to WebmasterWorld Guest from 54.198.2.110

Forum Moderators: Ocean10000 & incrediBILL & phranque

Need a MAMP Extensionless URL Fix

it's not rewriting .html requests

     
7:25 pm on Oct 21, 2017 (gmt 0)

Senior Member

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

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


I haven't used MAMP for several years so a bit rusty. I have spent about 12 hours since yesterday researching it again. I have MAMP set up and it's working for most htaccess requests (rewrite to non-www, loading custom 404 for typos, parsing files). BTW, I had to write in the full url for the custom 404 to get it to work.

However, the extensionless rewrite isn't working (I got it off an old JD Morgan page of instructions on the same) as the explanations help to explain what's going on..

When I enter localhost/example.com in the browser all pages load with all images as expected.

When I try to test to see if the extensionless URL is working by typing in a page.html, i.e.,
localhost/example.com/contact.html
it goes from localhost to the actual domain (which doesn't have this file loaded yet). It shows the data of the custom 404 page but the header,menu, footer aren't loading. Here is the path (which is an error as this site is only 2 levels deep):
http://example.com/home/user/public_html/contact.html
It was doing the same thing before I added the full url to the ErrorDocument 404

I have the rewrite to non-www below this bit of code and it's working.

Can someone see my mistake below?
--
Here is the relevant htaccess: (I have example changed to actual domain in the original file)

RewriteEngine on
#
#EXTENSIONLESS URL FIX
# Internally rewrite extensionless file requests to .html files ##
# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
# and if it does not exist as a directory
RewriteCond %{REQUEST_FILENAME} !-d
# and if it does not exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# then add .html to get the actual filename
RewriteRule (.*) /$1.html [L]
#
# Externally redirect clients directly requesting .html page URIs to extensionless URIs
# If client request header contains html file extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP
# externally redirect to extensionless URI
RewriteRule ^(.+)\.html$ http://example.com/$1 [R=301,L]
#
6:04 pm on Oct 27, 2017 (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


RewriteCond %{THE_REQUEST} \.html
RewriteRule \.html$ /%1 [R=301,L]
Was this edited for posting? As written, there is no capture from the final Condition, making %1 empty, which means that everything would end up at the root.
4:51 pm on Oct 28, 2017 (gmt 0)

Senior Member

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

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


I must have misunderstood your comments on msg#4873642 (page 1 of this discussion).

You said to replace this:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP
with this:
RewriteCond %{THE_REQUEST} \.html

which leaves:
RewriteCond %{THE_REQUEST} \.html
RewriteRule \.html$ /%1 [R=301,L]

Did I misunderstand?
5:59 pm on Oct 28, 2017 (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


You've already captured in the body of the rule
6:03 pm on Oct 28, 2017 (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 back and reviewed comments re the extensionless code for htaccess and changed it to this:

ErrorDocument 404 /missing.html
AddHandler server-parsed .html
#
Options +FollowSymLinks +Includes
RewriteEngine on
#
#External redirect for extensionless url
RewriteCond %{THE_REQUEST} \.html
#While on Localhost http://www.example.com is removed before / slash in the following
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
#
# Internal rewrite for extensionless url
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /$1.html [L]
#

===
Now when I type in faqs.html it goes to the faq page with the html removed, like it should.

However if, from the faqs page, I then click on any of the links in the menu it throws a 404 again and according to the live header it is looking for the css file, script for menu, images, within a folder in that page instead of the root.

Is there still someone wrong with the above code?
6:05 pm on Oct 28, 2017 (gmt 0)

Senior Member

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

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


PS. If I purposely type in a typo it reverts to the 404 page on localhost with all images, scripts, css intact and working like it should.
8:21 pm on Oct 28, 2017 (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:11078
votes: 106


However if, from the faqs page, I then click on any of the links in the menu it throws a 404 again


you need to describe your above quote in terms of The Request that was sent by your browser, the relevant HTTP Request headers, ...
11:15 pm on Oct 28, 2017 (gmt 0)

Senior Member

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

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


here it is:


http:/localhost/faqs/

GET /faqs/ HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) Gecko/20100101 Firefox/56.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/faqs
Cookie: sc_is_visitor_unique=rx11463677.1508953424.EA25315350584FFF2F98A896A7A21A55.14.13.9.8.7.6.1.1.1
Connection: keep-alive
Upgrade-Insecure-Requests: 1

HTTP/1.1 404 Not Found
Date: Sat, 28 Oct 2017 23:11:29 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.8zh DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Accept-Ranges: bytes
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
http:/localhost/faqs/aascc.css

GET /faqs/aascc.css HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) Gecko/20100101 Firefox/56.0
Accept: text/css,*/*;q=0.1
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/faqs/
Cookie: sc_is_visitor_unique=rx11463677.1508953424.EA25315350584FFF2F98A896A7A21A55.14.13.9.8.7.6.1.1.1
Connection: keep-alive

HTTP/1.1 404 Not Found
Date: Sat, 28 Oct 2017 23:11:29 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.8zh DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Accept-Ranges: bytes
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
http://localhost/faqs/script.js

GET /faqs/script.js HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) Gecko/20100101 Firefox/56.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/faqs/
Cookie: sc_is_visitor_unique=rx11463677.1508953424.EA25315350584FFF2F98A896A7A21A55.14.13.9.8.7.6.1.1.1
Connection: keep-alive

HTTP/1.1 404 Not Found
Date: Sat, 28 Oct 2017 23:11:29 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.8zh DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Accept-Ranges: bytes
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
http://localhost/faqs/images/smart-chiro-logo320b.jpg

GET /faqs/images/smart-chiro-logo320b.jpg HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) Gecko/20100101 Firefox/56.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/faqs/
Cookie: sc_is_visitor_unique=rx11463677.1508953424.EA25315350584FFF2F98A896A7A21A55.14.13.9.8.7.6.1.1.1
Connection: keep-alive

HTTP/1.1 404 Not Found
Date: Sat, 28 Oct 2017 23:11:29 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.8zh DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Accept-Ranges: bytes
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
http://localhost/faqs/script.js

GET /faqs/script.js HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) Gecko/20100101 Firefox/56.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/faqs/
Cookie: sc_is_visitor_unique=rx11463677.1508953424.EA25315350584FFF2F98A896A7A21A55.14.13.9.8.7.6.1.1.1
Connection: keep-alive

HTTP/1.1 404 Not Found
Date: Sat, 28 Oct 2017 23:11:29 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.8zh DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Accept-Ranges: bytes
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
http://localhost/faqs/images/smart-chiro-logo320b.jpg

GET /faqs/images/smart-chiro-logo320b.jpg HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:56.0) Gecko/20100101 Firefox/56.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/faqs/
Cookie: sc_is_visitor_unique=rx11463677.1508953424.EA25315350584FFF2F98A896A7A21A55.14.13.9.8.7.6.1.1.1
Connection: keep-alive

HTTP/1.1 404 Not Found
Date: Sat, 28 Oct 2017 23:11:29 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.8zh DAV/2 mod_perl/2.0.8 Perl/v5.20.0
Accept-Ranges: bytes
Keep-Alive: timeout=5, max=97
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
12:24 am on Oct 29, 2017 (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


Why is the browser requesting /faqs/ when it is supposed to be requesting /faqs (rewritten to /faqs.html)?

Why does the 404 page use relative links?
12:50 am on Oct 29, 2017 (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:11078
votes: 106


Now when I type in faqs.html it goes to the faq page with the html removed, like it should.

i assume this means a request for http://localhost/faq.html get a 301 status code with a Location header referring to http://localhost/faq which would be the extensionless url.
the subsequent request for http://localhost/faq would be internally rewritten to /faq.html and i assume this response is a 200 status code with the proper content.
correct so far?

http:/localhost/faqs/

GET /faqs/ HTTP/1.1

this is a request for the trailing slash url, not the extensionless url.
does the /faqs/ subdirectory exist under the document root directory?
your server error log would probably tell you that the directory doesn't exist.
12:07 pm on Oct 29, 2017 (gmt 0)

Senior Member

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

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


@Lucy24

Why is the browser requesting /faqs/ when it is supposed to be requesting /faqs (rewritten to /faqs.html)?


I don't know.

Why does the 404 page use relative links?


The 404 page uses an include for the menu like all the other pages which are currently relative links (the original site uses full urls).

@phranque

the subsequent request for [localhost...] would be internally rewritten to /faq.html and i assume this response is a 200 status code with the proper content.
correct so far?


I don't understand why it's reverting back to the /faq.html. Why does it rewrite it again?

http:/localhost/faqs/

GET /faqs/ HTTP/1.1


this is a request for the trailing slash url, not the extensionless url.
does the /faqs/ subdirectory exist under the document root directory?
your server error log would probably tell you that the directory doesn't exist.


There is no /faqs/ sub directory. There are about 12 pages all in the root including the faqs.html page along with the scripts. the images, are in an image subdirectory So why it's looking for a /faqs/ subdirectory or images within that directory I have no idea. That's what I've been trying to find out since my first post on this subject.

The pages are arranged like this.

content.html
faqs.html
/images/
index.html
script.js
8:03 pm on Oct 30, 2017 (gmt 0)

Senior Member

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

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


I found the error log on MAMP and tried again. when I go to local host and enter faqs.html the faq page comes up like it should. then I click on Faqs in the menu and it throws an error (I also tried adding a slash in front of faqs.html in the menu link with the same result --see from 12:57pm for the later) .

here are the results (it is looking for a directory called /faqs/ when there is no such directory.


[Sun Oct 29 05:07:51 2017] [notice] caught SIGTERM, shutting down
[Mon Oct 30 12:50:51 2017] [notice] FastCGI: process manager initialized (pid 14152)
[Mon Oct 30 12:50:53 2017] [notice] Digest: generating secret for digest authentication ...
[Mon Oct 30 12:50:53 2017] [notice] Digest: done
[Mon Oct 30 12:50:53 2017] [notice] 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.8zh DAV/2 mod_perl/2.0.8 Perl/v5.20.0 configured -- resuming normal operations
[Mon Oct 30 12:52:19 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs
[Mon Oct 30 12:52:19 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs/
[Mon Oct 30 12:52:19 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs/
[Mon Oct 30 12:52:19 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs/
[Mon Oct 30 12:52:19 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs/
[Mon Oct 30 12:52:19 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs/

Mon Oct 30 12:57:19 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs
[Mon Oct 30 12:57:19 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs/
[Mon Oct 30 12:57:19 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs/
[Mon Oct 30 12:57:19 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs/
[Mon Oct 30 12:57:20 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs/
[Mon Oct 30 12:57:20 2017] [error] [client ::1] File does not exist: /Applications/MAMP/htdocs/faqs, referer: http://localhost/faqs/
4:51 pm on Nov 2, 2017 (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 what was causing the problems -- slashes on the end of links to the pages, i.e., page1/
Once I took those off everything worked except for items in a folder.

Can someone tell me what needs to change to so items in a folder will do the same. The site is arranged like this:

page1
page2
folder/page1b
page2b
page3b
page3
page4
page5

Here is the code I'm using:


ErrorDocument 404 /missing.html
AddHandler server-parsed .html
#
Options +FollowSymLinks +Includes
RewriteEngine on
#
#External redirect for extensionless url
RewriteCond %{THE_REQUEST} \.html
#While on Localhost http://www.example.com is removed before / slash in the following
RewriteRule ^(.+)\.html$ /$1 [R=301,L]
#
# Internal rewrite for extensionless url
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /$1.html [L]
7:52 pm on Nov 2, 2017 (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:11078
votes: 106


Once I took those off everything worked except for items in a folder.

Can someone tell me what needs to change to so items in a folder will do the same.

the description?...
10:14 pm on Nov 2, 2017 (gmt 0)

Senior Member

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

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


?. Description of what?

I would like pages in a folder to operate the same as pages in the root.
7:53 am on Nov 3, 2017 (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:11078
votes: 106


?. Description of what?

describe what happens when you request http://localhost/folder/page1b or similar urls.
you need to describe ... in terms of The Request that was sent by your browser, the relevant HTTP Request headers, the status code of the HTTP Response, the relevant HTTP Response headers, and the body of the response.
you should include the entire chain of redirects, if any, in your description.
in all descriptions you should include what you expected to see and what you actually observed.
6:07 pm on Nov 3, 2017 (gmt 0)

Senior Member

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

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


When I tired it this morning most everything is working (localhost/page), l(ocalhost/folder/page) and live header produces a 200 for everything. I always empty the cache so not sure why it wasn't working the other day. I haven't changed anything other than logging in and out of Mamp.

Only problem now is when I'm on one of the pages within the folder and click on one of the items in the menu (that is not in the folder), it throws a 404 because it isn't seeing the css file and one of the scripts from within that folder. I have all includes set up with ../ to pick up those files from the root. I assume this is occurring because while on MAMP I can't use full urls in the includes. I"ll do some more testing and post the live headers if I can't figure it out.
2:23 pm on Nov 5, 2017 (gmt 0)

Senior Member

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

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


The live website uses full urls so the problem mentioned above doesn't occur once these files go online.

I loaded all files to the live site and all pages are working correctly except one which has a list of pages in a folder/directory. The page itself is an html page with data on it, not a faux category head in the menu.

I clicked from one of the other pages in the top menu onto this page and the live header shows that the html was removed from this page, like it should, then a 301 adds a slash on the end of it and it throws a 403.

the referrer is one of the pages within that directory (the one on the end of the list of links) but that isnít where I clicked last. I was on one of the top menu items before I clicked on this page.

I can click within that directory to the pages inside and they are working correctly. This is the only error on the site.

I have checked everything over and canít find the error. I tried adding a slash on the end of this page in menu thinking the browser thinks itís the head of a category but that didnít work either. I finally restored everything to the live site until I can figure it out.

Should I set this site up as a faux category with javascript and put this page within the folder/directory or is there another fix via the extensionless code.

Here is how the pages are arranged


example.com
page1
page2
page3 (this is the page causing a problem with links to pages in directory - ignore hyphens)
---page1a
---page2a
---page3a
page3
page4
page5
page6
3:07 pm on Nov 7, 2017 (gmt 0)

Senior Member

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

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


Ok, I figured out my problem re the pages in the folder. I needed to put an index file in there.

@lucy24
@phranque

Thanks for your help in trying to help me get this working, and especially your patience. I had several errors which made it difficult to figure out.
4:12 pm on Nov 7, 2017 (gmt 0)

Senior Member

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

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


Just one more question. when all pages have been changed over to extensionless URLs, is this the correct way to write a redirect for one of the pages which is now the main page in a folder? I"m not sure, because they are now set to have no .html, if I should leave the html on both or take them off.

RewriteRule ^oldfilename\.html$ http://www.example.com/folder/index.html [R=301,L]
This 49 message thread spans 2 pages: 49
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members