Jump to content

Htaccess Help


driz

Recommended Posts

Hi, I'm developing a forum and the home page is index.phpWhat I want to happen is the index.php always be shown when accessing the home page, so for example if you go to domain.com/forums/It would auto correct this to domain.com/forums/index.phpIt seems that htaccess would be the best system for this, how would I go about doing it?I tried this:

Redirect 301 /forums /forums/index.php

BUT it just loops and loops and never ends the redirect. Thanks

Link to comment
Share on other sites

You shouldn't need anything at all. If your server is configured the normal way, index.php will automatically be used when somebody puts the path to the folder.

Link to comment
Share on other sites

Rather than redirect, you would probably want URL rewriting, I think this should work:

RewriteEngine OnRewriteRule ^forum[/]? forum/index.php

Link to comment
Share on other sites

Rather than redirect, you would probably want URL rewriting, I think this should work:
RewriteEngine OnRewriteRule ^forum[/]? forum/index.php

Thanks for the reply. That rule isn't working though, it's just doing the default behaviour.
Link to comment
Share on other sites

After testing on my computer, the code that would do what you want it to is

RewriteRule ^forum[/]?$ http://yourdomain.com/forum/index.php [R=301,L]

You'll have to use a full URL as the second parameter, since it's a form of redirect.

Link to comment
Share on other sites

It's still not working :/Here is the full code I have in place:

RewriteEngine OnRewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]RewriteRule ^(.*)$ http://%1/$1 [R=301,L]RewriteCond %{REQUEST_FILENAME} -f [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^(.+) - [PT,L]RewriteRule ^(.*) index.phpAddHandler php5-script .phpRedirect 301 /vii http://driz.co.uk/VIIRewriteRule ^forums[/]?$ http://driz.co.uk/forums/index.php [R=301,L]

Link to comment
Share on other sites

It possibly isn't working because it is still within the conditions stated previously (is not a file or directory).Try putting a RewriteCond for this one.

RewriteCond %{REQUEST_URI} ^/forums[/]?$RewriteRule ^forums[/]?$ http://driz.co.uk/forums/index.php [R=301,L]

Link to comment
Share on other sites

RewriteEngine OnRewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]RewriteRule ^(.*)$ http://%1/$1 [R=301,L]RewriteCond %{REQUEST_FILENAME} -f [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^(.+) - [PT,L]RewriteRule ^(.*) index.phpAddHandler php5-script .phpRedirect 301 /vii http://driz.co.uk/VIIRewriteCond %{REQUEST_URI} ^/forums[/]?$RewriteRule ^forums[/]?$ http://driz.co.uk/forums/index.php [R=301,L]

That's how it looks at now, but it still isn't working :/

Link to comment
Share on other sites

Try removing the "L" modifier from the previous rewrites. They possibly are causing the engine to stop before reaching this one.The condition works correctly when I test it on my computer.

Link to comment
Share on other sites

I don't use htaccess much, but am I correct in assuming that using a rewrite rule will not change the URL as it appears in the browser, only how the URL is handled on the server? Wouldn't you need a redirect?

Link to comment
Share on other sites

I don't use htaccess much, but am I correct in assuming that using a rewrite rule will not change the URL as it appears in the browser, only how the URL is handled on the server? Wouldn't you need a redirect?
[R=301] The 'R' modifier redirects giving an HTTP response while doing so. The advantage is that you can make it redirect from certain URLs but not others depending on how they're written rather than where they point.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...