Domain Empire

Problems with mod_rewrite

Spaceship Spaceship
Watch

gee

Established Member
Impact
10
Hi

I'm working on the simple website that must have seo-freindly links.
I have never used mod_rewrite since today so I really need some help to make it work.

This is the content of my htaccess file. It works only partially.

RewriteEngine On
RewriteRule ^([^/.]+)/?$ product.php?product=$1 [L]
RewriteRule ^misc/contact$ contact.php [L]
RewriteRule ^misc/about$ about.php [L]


When I enter the address: mysite.com/printer everything is OK, I got what I want - page shows printer.
But when I enter mysite.com/misc/about I got "about" page with missing graphics and every link on the page is changed and contains "misc" prefix now.
They looks as follows:

mysite.com/misc/contact.php (should be mysite.com/contact)
mysite.com/misc/about.php (should be mysite.com/about)
mysite.com/misc/index.php (should be just mysite.com)
etc.

All php files are in the same directory.

What did I wrong? Can anyone help me?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Looks like prob is in the urls in your about page, not in the .htaccess rules.

They probably go to "contact.php" instead of "/contact.php" for example.
 
1
•••
Actually my first post describes things a bit different than they were in reality. It's because I was writing from memory, not looking into scripts. It would be misleading for future readers, that have similar problem and look for solution. I can't edit that post anymore, so I post edited fragments here:

RewriteEngine On
RewriteRule ^([^/.]+)/?$ product.php?product=$1 [L]
RewriteRule ^misc/contact$ contact.php [L]
RewriteRule ^misc/about$ about.php [L]
RewriteRule ^something/link$ link.php [L]
RewriteRule ^somethingelse/link$ anotherlink.php [L]
etc.

It looks as follows:

mysite.com/misc/something/link (should be mysite.com/something/link)
mysite.com/misc/somethingelse/link (should be mysite.com/somethingelse/link)


Anyway, the problem was - as you said - missing slashes in every link in my PHP files.
I added slashes (also to the graphics folder and CSS file) and now everything seems to work fine.

Thanks a lot @carob :)
 
1
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back