Forum Moderators: phranque

Message Too Old, No Replies

simple .htaccess rewrite

It's simple but I don't know how to

         

dotsLedzfer

8:27 am on Jun 25, 2008 (gmt 0)

10+ Year Member



I'm a newbie at .htaccess, what I gonna to do is rewrite my page, such as:
http://example.com/page/about.htm

Rewrite to this:
http://example.com/about

I'm not sure If It's possible to do this with .htaccess, I test several time at still don't work, hopefully somebody can help me.

Regards.

[edited by: jdMorgan at 3:33 pm (utc) on June 25, 2008]
[edit reason] example.com [/edit]

jdMorgan

3:33 pm on Jun 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi dotsLedzfer,

Yes, it's possible.

Please have a look through our Apache forum library, and see the documents cited in our Forum Charter for more info. Then post your best-effort code as a basis for discussion.

A search of this forum for "extensionless URLs rewrite" may also be helpful.

Thanks,
Jim

dotsLedzfer

8:29 am on Jun 26, 2008 (gmt 0)

10+ Year Member



Thanks for your help, I'll search before I asking, mainly reason I post because I don't know what's the keyword.
That's my .htaccess I write before, I made it simple, but still doesn't work.

RewriteEngine on
RewriteRule ^/(.*)$ http://example.com/page/$1.htm

I know my code a bit foolish, but indeed, I think It could be solve with few lines. Thanks you help.

jdMorgan

6:18 pm on Jun 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps something like:

RewriteEngine on
#
# If requested URL-path does not contain a period or slash in the final path-part
RewriteCond $1 ^([^/]+/)*[^./]+$
# rewrite to add "/page" subdirectory path and ".htm" to the URL-path
RewriteRule ^(.+)$ http://example.com/page/$1.htm

Jim

dotsLedzfer

5:36 pm on Jun 27, 2008 (gmt 0)

10+ Year Member



It's wired, It'll be automated redirect to about.htm, not /about. I'm try to made another one by my hand also, but the result was the same.

RewriteEngine on
RewriteRule ^/?([a-z]+)$ http://example.com/page/$1.shtml [L]

Thanks for your help.