Forum Moderators: phranque

Message Too Old, No Replies

To get rid of dummy text in URL

         

eta_carinae

12:30 am on May 14, 2011 (gmt 0)

10+ Year Member



Hello,

a part of my site is stored in some /long/dummy/text/ folder

how am I able to rewrite URLs to replace this /long/dummy/text/ part with nothing and return it to browser? :)

now - [site.com...]
i want - [site.com...]

Sorry, that should be easy, but I can't find it :(

lucy24

1:41 am on May 14, 2011 (gmt 0)

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



Oops, your examples got eaten by the site code. Always use www.example.com so people can see what you typed.

Do you mean that you want users to be able to enter
example.com/shortaddress
and be silently rerouted to
example.com/long/dummy/text/shortaddress ?

The minimalist version is
RewriteRule /shortaddress long/dummy/text/shortaddress [L]

but the details are going to depend on what exactly "shortaddress" is. Do you have a finite number of named files that isn't likely to change? A bunch of files whose names all fit the same pattern, like "news20110512" "news20110513" etc? Do you have any files that actually do live at /shortaddress so you have to prevent them from being redirected? All of those things will determine what, if anything, needs to go in a RewriteCond line before the Rule.

g1smd

7:15 am on May 14, 2011 (gmt 0)

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



The first step is to link to the URL that you want users to see and use. URLs are defined in links. Mod_rewrite cannot change the links on your pages.

Once you link to the right URL, you need an internal rewrite to connect that URL request to the non-default internal server location that will serve the content.

You also optionally need an external redirect that detects requests for the old URL, perhaps clicked in a stale SERP or from browser bookmarks, and which then redirects to the new URL.

Use
RewriteRule
syntax for both. The redirect will need the
[R=301,L]
flags and will have a preceding
RewriteCond
testing
THE_REQUEST
to ensure only direct client requests are redirected. The rewrite will have the
[L]
flag and must not mention the domain name.

There are thousands of prior examples in this forum as it is a question that has been asked almost every week for the last decade in one form or another.