Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I have an HTML page in my root directory, and when someone clicks it I'd like there to be a directory before the file name, that doesn't exist.

For example, instead of just being able to access:

wwww.example.com/link.html

This would also work:

wwww.example.com/folder/link.html

Can this be done with a rewrite rule?

share|improve this question
    
Can you clarify this a bit more? Do you mean they'd click a link to wwww.example.com/link.html but be forwarded to wwww.example.com/folder/link.html? And what's not created, the directory /folder? –  dan Dec 16 '13 at 0:40
    
yes, i just want it as you you'd see in wordpress links etc –  tom Dec 16 '13 at 0:46
    
I have some URLS and I want to add a a specific word before the link.html so its like a keyword e.g. www.example.com/townname/link.html www.example.com/townname/link2.html can that not be done with a rewrite rule / permalink? –  tom Dec 16 '13 at 1:06
    
Edited your question based on your comments and reopened it. –  dan Dec 16 '13 at 20:35
1  
The functionality of mod rewrite per the wordpress and other CMS application is not to serve as such a redirect, but instead in order to "prettify" otherwise abstract linkage because the site is database driven. A common URL for a CMS would be example.com/index.php?page=somepageid. The rewrite rule is designed to make a pretty url that is SEO friendly. What is your purpose in trying to use this? Adding a non-existant directory to the URL is only going to break several web standards, and potentially confuse your visitors. –  tremor Dec 16 '13 at 20:48

1 Answer 1

Your rewrite rule (appropriate for a .htaccess file) would look like this:

RewriteRule ^folder/link.html$ /link.html

That would serve the contents of link.html at both /link.html and /folder/link.html.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.