Welcome to WebmasterWorld Guest from 54.162.139.105

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

.htaccess redirect using a page with no file extension

     
1:27 pm on Apr 7, 2014 (gmt 0)

New User

joined:Apr 7, 2014
posts: 2
votes: 0


i have tried a few way to do this but nothing has worked. What i want to do is re-direct people to a page on my site that has a rather long URL. I want to just have a simple url listed on an advertisement page that just has a one word url following the domain, like www.example.com/ad

I have used a PHP re-direct in the past but the page had an extension, when i re-named without the extension the page will not run the re-direct and just displays the page as raw text in the browser.

I tried to do the .htaccess redirect using the normal

Redirect /example.com/as http://example.com/12345789.html

but this is also not working at all and still just showing the raw text in the browser. I have the .htaccess file in the same level of the ftp server as the file page that has the re-direct, is this correct?

So in short i need to have my page with no file extension re-direct to another page when its typed directly in the browsers URL box.
4:19 pm on Apr 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


Why on earth do you want to redirect a short extensionless URL to a longer one with an extension? I strongly suspect you're missing a rewrite somewhere; I have to assume the physical files on your server have extensions.

Step one, then, is to take ALL rules that currently use mod_alias (Redirect by that name) and convert them to mod_rewrite syntax, because everything needs to be in the same form. Come back when you've done that part.

Next step will have two parts:
redirect from old with-extension URL to new without-extension form
and
rewrite new extensionless URL to serve content from wherever it happens to live.

Happily there are at least 80,000 threads in this subforum addressing the question.
8:02 pm on Apr 7, 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


welcome to WebmasterWorld, krazyjoe!


the key to what lucy24 said is that you first need to understand what an internal rewrite is vs. an external redirect.

Redirect /example.com/as http://example.com/12345789.html


since you probably want an internal rewrite for this rule, the Redirect (a mod_aliaS directive) is wrong for this purpose.
in addition, the Redirect directive looks at path information only and you can't examine the hostname unless you use mod_rewrite directives (RewriteCond).
8:51 pm on Apr 7, 2014 (gmt 0)

New User

joined:Apr 7, 2014
posts: 2
votes: 0


Thanks for the replies. I only recently switched over to a Linux based server running Apache so this is all completely new.

I guess two start should i be using .htaccess or should i just use code in the page that is going to be doing the re-directing. The reason im doing this is because im creating an add for people to come to our e-commerce web site. The e-com site generates pages and the code so i don't really have control over the urls and it make them very long. This is why i want to just have a simple word after my domain name so its easy to type in and also remember. This is why i want them page to not require an extension like .html or .php. Just again to simplify things.
10:02 pm on Apr 8, 2014 (gmt 0)

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


Effectively you want a "short URL" to advertise elsewhere.

In this case, a redirect using RewriteRule and [R=301,L] seems appropriate.
2:16 am on Apr 9, 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


should i be using .htaccess or should i just use code in the page

If those are your two choices, go with htaccess. In-page redirects are generally a last resort.