.htaccess mod_rewrite issue

New to mod_rewrite? This is a good place to start.

.htaccess mod_rewrite issue

Postby eliassot » Tue Jun 02, 2009 6:36 am

Hi guys,

I'm new to this and I would appreciate some of your expertise :-)

I'll let you know what I'm trying to do:

I have a small website with static pages and I just want to remove the extension .php from my files.
After lots of tries I came up with this

RewriteRule ^([A-Za-z0-9]+)/?$ $1.php [L]

That works fine when I type www.example.com/company but when I type www.example.com/company/ (slash at the end) I loose the css and the images.
Besides that when I type www.example.com/company/about or any other page on a folder other that root, I get a 404 not found page.

Could anyone help me solve this?

Thank you in advance :-)
eliassot
 
Posts: 2
Joined: Tue Jun 02, 2009 6:35 am

Postby richardk » Tue Jun 02, 2009 10:59 am

That works fine when I type www.example.com/company but when I type www.example.com/company/ (slash at the end) I loose the css and the images.

FAQ: Relative paths to images, JavaScript, CSS and other external/linked files are broken.

Besides that when I type www.example.com/company/about or any other page on a folder other that root, I get a 404 not found page.

Code: Select all
^([A-Za-z0-9]+)/?$

only matches letters, numbers and a single, optional, trailing slash.

I take it /company/about goes to /company/about.php. Then you want
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Make sure the PHP file exists.
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([a-z0-9]+(/[a-z0-9]+)*)/?$ /$1.php [NC,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby eliassot » Tue Jun 02, 2009 12:09 pm

The problem is solved.

Thx for yr response :-)
eliassot
 
Posts: 2
Joined: Tue Jun 02, 2009 6:35 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 112 guests

cron