homepage Welcome to WebmasterWorld Guest from 54.205.241.107
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

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

Apache Web Server Forum

    
Redirect 404 to root, return 404 code and rewrite URL in address bar
.htaccess redirects
Bill_Brine



 
Msg#: 4507521 posted 5:04 pm on Oct 12, 2012 (gmt 0)

I'm just learning .htaccess and I've been searching online for a solution to this. I've found a number of related things and now am more confused.

Here's the situation: my client wants to do the following:

1) Redirect all 404s to the root
2) Return code 404 rather than 200 or 301
3) The final URL that appears in the address bar should read example.com, not example.com/index.html

The site use HTML. The site has PHP added as the handler for HTML files.

Can someone help me make sense of this?

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4507521 posted 8:55 pm on Oct 12, 2012 (gmt 0)

1) Very bad idea. Requests for pages that do not exist should be returned as 404 status, not 301 or 302.
2) Yes. Returning 404 is the right thing here.
3) The URL that appears in the address bar is the one that the user clicked on in the href="" part of the on-page link. URLs are defined in links. htaccess cannot change nor "make" a URL.

You can easily redirect requests for named index pages to URL ending with a trailing slash and the DirectoryIndex directive can be used to link the new request to the internal file that will serve the content. The redirect code has been posted several thousand times before in this forum.

You have the action of mod_rewrite exactly backwards. mod_rewrite cannot "make a URL for a file". Only links make URLs. mod_rewrite acts on the request only after the link is clicked. The RewriteRule alters where inside the server the content will be fetched from.

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