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

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

Apache Web Server Forum

This 35 message thread spans 2 pages: 35 ( [1] 2 > >     
Redirect pages.
TheKiller




msg:4268725
 10:49 pm on Feb 17, 2011 (gmt 0)

Ok so i have a phpbb forum with a portal mod ...

im using this for a while to redirect from the main domain (ex. example.com)to the Forums folder

Redirect 301 /index.php http://www.example.COM/Forums

but i dont want the domain to link to the index anymore ..

i want to link the domain to /Forums/portal.php
and not /Forums/index.php as the code above dos ...


i tried to change the index with the portal like this :
Redirect 301 /portal.php http://www.example.COM/Forums

but it gives me a 404 error.. any idea whats up?

Also i would like some fix for caps on folders ..

im on a Linux system and if i have a folder called Forums it gives me a error if i try browsing to forums(no caps on F)

 

jdMorgan




msg:4268823
 4:39 am on Feb 18, 2011 (gmt 0)

It looks to me like you're using external redirects when you should be using internal rewrites, and that you've got URLs confused with internal server filepaths.

Define the filepath to which your directory-index URL should resolve using the DirectoryIndex directive, as is
DirectoryIndex index.php
or
DirectoryIndex portal.php

These two lines map requests for the URL example.com/ to the server filepath /index.php or /portal.php respectively. So a link to a URL like example.com/Forums/ will invoke the file at /Forums/index.php or /Forums/portal.php

"Fixing caps on folders" is also unclear, since "folders" implies a filepath, but you can simply rename those, so that should never be a problem. I suspect you mean you need to accept and correct capitalization errors in requested URL-path-parts, but I cannot be sure.

I can say that mod_rewrite and other .htaccess-usable modules are quite lousy (inefficient) at dealing with capitalization -- or with any kind of character-substitution. This is because no recursion is supported, so you can only "change characters" one at a time.

This is all server configuration stuff, and attention to correct terminology and details is required for success. So if you could put your questions in terms of what URL you want to resolve to what server filepath, and what URL you want to replace with what other URL in search results listings, it would greatly simplify things...

Also be aware that Redirect 301 /x http://www.example.com/y redirects a request for
[exmple.com...] to http:www.example.com/y
but it also redirects a request for
[exmple.com...] to http:www.example.com/yabc/def.ghi
The Redirect directive uses prefix-matching and any part of the requested URL-path not specified in the matched prefix is "copied over" to the output URL. This is likely not what you want, and RedirectMatch would likely be a better choice. Also, if you have any RewriteRules whatsoever, or if you ever plan to use any, then do not use either Redirect or RedirectMatch, or you won't be able to control the order of execution of these directives ... it will be the server and not you that decides whether to process mod_alias Redirect and RedirectMatch directives first, or to process the mod_rewrite RewriteRules first... Mixing these two modules' directives can lead to all sorts of bizarre problems and devastation of your search ranking...

As above, this is server config stuff, and should be treated like dynamite... very old and unstable dynamite, in fact.

Jim

TheKiller




msg:4269127
 5:58 pm on Feb 18, 2011 (gmt 0)

Hi

i have no index set to the main root
i just want to redirect the Root to Forums/portal.php

if i use /Forums/portal.php it wont load well due to the CSS Links that are being broken wthout the Forums in the link

Something like this will be nice..

Redirect 301 / http://www.example.com/Forums/portal.php

the slash meaning the root... but i dont want the portal.php to show in the link.. i just want it to be accessed/opened


sorry i havent explained that well...
if you visit www.example.com/Forums all is fine as the folder with caps exists.....

if you try to browse to www.example.com/forums you will get a 404 error as the forums folder without caps dosnt exist

jdMorgan




msg:4269301
 12:21 am on Feb 19, 2011 (gmt 0)

Use DirectoryIndex to declare the index page filepath.

Then rewrite all requests for /whatever to /Forums/whatever if needed to fix the CSS, image, and .js linking problems.

In this way, your forums can be accessed via just your example.com/ URL, and your site won't look 'weird' to search engines.

Jim

TheKiller




msg:4269331
 1:29 am on Feb 19, 2011 (gmt 0)

Hello Jim

sorry but i dont understand much of what you are saying .....

here is my boards url [rising-dead.com...]
i'll deete the url later .....
when i access the link above i want it to redirect to [rising-dead.com...]

thats ment to be the home page

jdMorgan




msg:4269488
 4:16 pm on Feb 19, 2011 (gmt 0)

That is my point entirely. It would be a big mistake -and completely unnecessary-- to use a redirect in this case. Having requests for your 'domain home page URL' invoke a redirect causes delays for users and for search engines, and to be blunt, looks quite amateurish to both.

The URLs that you publish on your pages need have absolutely no relationship to the filesystem paths used by your server to access stored pages. There is no reason that you cannot link to risingdead.com/ and serve a page from /Forums/ without a client redirect.

Go to Apache.org, select your server version, and read the documentation for the DirectoryIndex directive in Apache mod_dir. Then spend several hours reading the Apache mod_rewrite documentation and looking at the examples in the URL Rewriting Guide. No it's not easy reading and may be quite confusing at first, but it is absolutely one of the best investments you can make in the future success of your site.

To put it in the opposite way, using Apache configuration directives without fully understanding their effects on your server's operation and on the search engine rankings of your site is a mistake that can literally put you out of business -- and quite quickly. In many cases, a single typo can be absolutely fatal.

I liken this to posting on a forum asking, "Hey, can someone give me a quick run-down on how to land a fighter jet on the pitching deck of an aircraft carrier at night? -- I don't have time to read the manuals or take all that training." It is not my intention to give you a hard time here. In fact, I'm addressing everyone who's in a similar situation and reads this. But honestly, to attempt to tell you how do do either of these things (modify your server or land the fighter jet) would be irresponsible of me if you're not understanding anything that I write. I can't in good conscience tell you how to commit SEO suicide, even if it is just one line of code.

Jim

TheKiller




msg:4271401
 9:56 am on Feb 24, 2011 (gmt 0)

Hello...

there is a reason as it wont load CSS Files and other things ,because phpbb detects their paths from the installed path of your board
for example " {T_THEME_PATH}/images/corners_left.gif " etc

i would need to edit all files and change the path .. and if i do that it would be retarded as i'll #*$! with the entire forums :D
even if i make it that way the forums (not portal) would get the linking to the css files broken

this line would be all i need ,but for some reason it dosnt work

Redirect 301 / http://www.example.com/

g1smd




msg:4271490
 2:45 pm on Feb 24, 2011 (gmt 0)

That final lines creates an infinite loop, redirecting from / to / to / to / to...

What was it meant to do?

TheKiller




msg:4274467
 8:25 am on Mar 1, 2011 (gmt 0)

Redirect / (Root) to /Forums

g1smd




msg:4274474
 9:12 am on Mar 1, 2011 (gmt 0)

The forum software lives in the /forum folder of your server, but do you want users to see "/forum" in the URL they use to access the forum?

If you use a rewrite, users can access the URL / and see the content from the /forum folder.

If you use a redirect, user asking for / will be redirected to the /forum folder and the URL shown the URL bar of their browser will change to show the new location. It is bad form to redirect the root of a site to an internal folder.

TheKiller




msg:4274525
 11:58 am on Mar 1, 2011 (gmt 0)

yep...
if you visit example.com to add /Forums into the link and create example.com/Forums

i have added this to my .htaccess file :

Redirect 301 /index.php http://www.rising-dead.com/Forums/
DirectoryIndex /Forums/portal.php Home.htm


if you visit
[rising-dead.com...] its all okay... the portal page shows as a main page correctly....

but if you visit [rising-dead.com...] the page is broken as it brakes the links to load the CSS Files from etc

i know there were some htacess scripts that added a slash at the end of the link .. is there a way to add /Forums at the end of the root?

g1smd




msg:4274531
 12:20 pm on Mar 1, 2011 (gmt 0)

If you use RewriteRule anywhere on your site, you must not use Redirect at all.

Use RewriteRule for all of your code, i.e. with the [R=301,L] flags.

The links to CSS, images, etc, are broken because they are relative
href="./styles/style.css" links. Change them to be href="/styles/style.css" links, with a leading slash, i.e. links that are relative to the root and they will again work. It is the browser that works out where things are, and with a relative link, the browser thinks the stylesheet is in the wrong folder.
TheKiller




msg:4274579
 2:22 pm on Mar 1, 2011 (gmt 0)

i think this is what you mean ...


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^rising-dead.com [NC]
RewriteRule ^(.*)$ http://www.rising-dead.com/$1 [L,R=301]
i got it from here http://www.webweaver.nu/html-tips/web-redirection.shtml

should i change [L,R=301] with [R=301,L] ?

i know the reason why they are broken .. read a few posts up when im talking about the {T_THEME_PATH}

if i change them i'll brake the way phpbb works with its styles ...

isnt there a easy way to do what i want ,untill i decide to make up with a different home page ?

also could you please tell me how can i fix the upercase thing etc on the folders?

like if u visit forums u get a 404 error as theres no forums and its Forums

Apologizes for my lame way of explaining myself .....

g1smd




msg:4274612
 3:05 pm on Mar 1, 2011 (gmt 0)

Several errors in that code. Try:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

TheKiller




msg:4274647
 3:51 pm on Mar 1, 2011 (gmt 0)

thank you but That Code isnt too much of importance ...
Can you please help me with the redirection thing ? :|

TheKiller




msg:4282734
 11:07 pm on Mar 16, 2011 (gmt 0)

Beep !

jdMorgan




msg:4283417
 1:14 am on Mar 18, 2011 (gmt 0)

Use RedirectMatch, and detect requests for either "/index.php" or just "/" then...

RedirectMatch 301 ^/(index\.php)?$ http://www.rising-dead.com/Forums/

Jim

TheKiller




msg:4287254
 9:14 am on Mar 25, 2011 (gmt 0)

Thank you Jim !

Is there a way not to display the url in the address bar?
Like browse to example.com and get the contents from example.com/forums/portal.php but in the address bar see the root
so it will behave as a directory index

g1smd




msg:4287269
 10:03 am on Mar 25, 2011 (gmt 0)

Yes. It is called a rewrite. The code for a rewrite is slightly different to that for a redirect, even though they both use the RewriteRule directive.

TheKiller




msg:4287629
 11:06 pm on Mar 25, 2011 (gmt 0)

Could someone try to show me some example ?

TheKiller




msg:4288332
 2:50 am on Mar 28, 2011 (gmt 0)

Guess not >,<

g1smd




msg:4288354
 7:37 am on Mar 28, 2011 (gmt 0)

There are tens of thousands of examples of rewrites and redirects in this forum.

A redirect looks like

RewriteRule ^old-path http://www.example.com/new-path [R=301,L]

A rewrite looks like

RewriteRule ^path-in-URL /path-inside-server [L]

but may be further complicated if either or both the URL used on the web or the server path inside the server use parameters.

TheKiller




msg:4291447
 1:06 pm on Apr 3, 2011 (gmt 0)

hmm... that thing looks like what im looking for !
But coulod you show me a better example of:
RewriteRule ^path-in-URL /path-inside-server [L]
with real paths ?
im a bit confused on how they should look like

path in url/addressform should be root and path inside the server should be something like /Forums/portal.php

g1smd




msg:4291451
 1:41 pm on Apr 3, 2011 (gmt 0)

The "path in URL" part is literally the bit after the www.example.com hostname all the way up to (but not including) the question mark before the query string (if there is a query string that is).

The "path inside server" is the location inside the server that will serve the content.

RewriteRule ^dogs /pets/cats.html [L]

When user requests www.example.com/dogs silently serve the file at /var/htdocs/pets/cats.html

Since RewriteRule can do pattern matching, the URL pattern is decided by the URL structure you use on your site.

TheKiller




msg:4291452
 1:49 pm on Apr 3, 2011 (gmt 0)

humm... im sorry but im still not understanding it quite well...

i dont have a "dogs" folder .. just the root
i tried:
RewriteRule ^index.php /Forums/portal.php [L]
but when i visited the root it gave a 404 error

I Want so when the user requests the root he will receive the contents of example.com/Forums/portal.php
but the link will just look like example.com
even if it received the content from a different url

g1smd




msg:4291463
 2:16 pm on Apr 3, 2011 (gmt 0)

User's don't "receive content from a different URL".

Users request a URL and the server fetches a file to serve that content. URLs and files are not at all the same thing. Understanding this is the key to understanding what rewriting actually does.

Usually the file inside the server is the same file as suggested by the path part of the URL.

With a rewrite, the file is a different file to that suggested by the path part of the URL, the RewriteRule being the thing that does the "translation".

RewriteRule ^index\.php /Forums/portal.php [L]

In the above example, user requests the URL example.com/index.php and the server fetches the file at /Forums/portal.php instead of the file at /index.php.

The index.php part of the rule matches the literal
GET /index.php HTTP/1.1 request sent by the browser.

If you request www.example.com/ only, then that URL request will not be matched by that rule and it will not return the file you wanted.

A modified rule could do it

RewriteRule ^$ /Forums/portal.php [L]

Now it will return the portal page if you ask for example.com/ without a path.

However, in this case, if you are talking merely about the root URL and no other URLs within your site, there is a simpler way to achieve what you want:

DirectoryIndex /Forums/index.php
TheKiller




msg:4291853
 3:10 pm on Apr 4, 2011 (gmt 0)

Hi

The First example gives me a 404 error (maybe because theres no index.php in the root O-o)

The Second/Middle example makes the page look the same as if i Add DirectoryIndex /Forums/portal.php
So thats not what i need...

This dos exactly what i want except that it shows the url in the address bar ..

RedirectMatch 301 ^/(index\.php)?$ http://www.example.com/Forums/portal.php

g1smd




msg:4291963
 7:48 pm on Apr 4, 2011 (gmt 0)

Yes, you will see the URL in the URL bar because your new code is for a redirect.

That is, if you request
www.example.com/index.php the server tells the browser to request a different URL. When the browser then requests www.example.com/Forums/portal.php the server fetches the file at /Forums/portal.php.

That is exactly what a redirect does. A redirect is a URL to URL translation. However, what you need is a rewrite, as explained in the previous posts. A rewrite is a URL to file translation.

Stop thinking only in terms of URLs. URLs are used out there on the web. Inside a server, there are only files. The job of a server is to translate external URL requests into an internal file fetch operation.

TheKiller




msg:4293666
 1:02 pm on Apr 7, 2011 (gmt 0)

Yeah.. but i was wondering if you could help me with a code that dos that function but not showing the link ..

Can you help me with such a rewrite code that dos the thing i want?

Also do you know how to play with the Linux charset thing or whatever?

For example i have a folder called Forums and i can access it

But i cant access a forum called forums (without caps on f)

g1smd




msg:4293835
 7:47 pm on Apr 7, 2011 (gmt 0)

Yes, all of the rules with just the [L] flag shown in the posts above are for simple rewrites.

Have you tried any of those?

This 35 message thread spans 2 pages: 35 ( [1] 2 > >
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