Forum Moderators: phranque

Message Too Old, No Replies

htaccess problem

newbie with htaccess problem

         

maryjiel

5:08 am on Oct 12, 2011 (gmt 0)

10+ Year Member



Good day Webmasters,

im seeking for help with htaccess. i have this url, which i want to solve by removing the .php in the url and have it like a directory. can anyone help me?

Here is what the URL looks like:

http://localhost/test/archive.php


Here is what i want the URL to be:

http://localhost/test/archive


i have heard that .htaccess is the only way to solve it. can any of you guys can help me? thanks in advance.

g1smd

6:32 am on Oct 12, 2011 (gmt 0)

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



This question is asked almost every day here.

On the pages of your site, link to the URL you want users to see and use.

Install a RewriteRule to rewrite requests for the URL example.com/test/archive to the internal filepath /test/archive.php.

Before that, install another RewriteRule to redirect external requests for the URL example.com/test/archive.php to the new URL at example.com/test/archive. This rule will also need a preceding RewriteCond looking at %{THE_REQUEST} to ensure that there is not an infinite rewrite-redirect loop.

There's more than 5000 previous threads with example code in this forum, at least five already so far just this month.

maryjiel

6:58 am on Oct 12, 2011 (gmt 0)

10+ Year Member



do you have any good example that can serve me as a reference. i am not yet familiar using htaccess and i want to see how it works.

g1smd

7:06 am on Oct 12, 2011 (gmt 0)

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



Pick a few threads from this list: [google.com...]

It will not take more than a few random clicks to find a question similar to yours with example code to adapt and try.

You've already got a clue what the code will look like. All you need to do is fill in the right RegEx patterns.

maryjiel

7:23 am on Oct 12, 2011 (gmt 0)

10+ Year Member



ok. before that tell me first if this is right. i got this from 9lessons.info showing the URL:

[twitter.com...]

it says that it uses a pattern,

RewriteEngine on
RewriteRule ^(.*)\$ $1.php

But when i tried this. it won't work...

if this is wrong please tell me.. i'll try to search on your searches that i might help me.

thanks.

g1smd

8:04 am on Oct 12, 2011 (gmt 0)

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



That code will create an infinite rewrite loop. I provided a link to posts with the correct code, don't know why you had to look at some other site.

The pattern for the rewrite should be
^([^/.]+)$
if the files are always in the root, and
^(([^/]+/)*[^/.]+)$
if the files are in either the root or in deeper folders.

You will also need to add the redirect code that I mentioned above, otherwise you will have a duplicate content issue too.