• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

mod_rewrite Problems...

zeroborg

Basic Pleskian
Hi all...

I can't make mod_rewrite to work.
I add the vhost.conf to /srv/www/vhosts/domain.com/conf with the following data:
===================
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /km/index.php?page=$1 [L]
===================

I run /usr/local/psa/admin/sbin/websrvmng -v -a

And when i try to see the result to page:
http://www.domain.com/km/index.php?page=1000
(which has to be retyped to: http://www.domain.com/1000.html )
nothing happens...
The rewrite works on the background. When i examined the logs of the rewrite engine i found that it PASSES THROUGH anything...
==================
(2) init rewrite engine with requested uri /km/index.php
(3) applying pattern '^([^/]*)\.html$' to uri '/km/index.php'
(1) pass through /km/index.php
==================

Does anyone knows why? Please advise.
Thank you.

Zeroborg.
 
I am confused.

Are you trying to rewrite the pattern *.html to /km/index.php?page=$1 or are you trying to rewrite the pattern /km/index.php?page=* to $1.html?

Your rewrite rule will match something.html and rewrite it to /km/index.php?page=something

Is that what you are trying to accomplish?
 
you should try it in...

.htaccess of the httpdocs.. I have managed to get it working on mine.

you don't need the Symlink part..
 
Alright, we are now on the same page.

You can do this in a couple of ways, but probably the easiest is going to be to create an .htaccess file in the root of the site.

Obviously you have mod_rewrite working.

Here is a sample of what I have been using for a similar rewrite situation. I will explain each line in a little more detail to help you understand what is going on.

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.html$ /km/index.php?page=$1 [L]

Here is what each line does:

RewriteEngine On

This turns on the rewrite engine

RewriteCond %{REQUEST_FILENAME} !-f

This line checks to make sure the requested file does not exist. This is handy to prevent requests for legitimate files from being passed through to the mod_rewrite rule that follows.

RewriteRule ^(.*)\..html$ /km/index.php?page=$1 [L]

This looks for anything ending in .html and passes the pattern before that to /km/index.php?page= in the value of $1.

A word of caution: this rule is "greedy" meaning it can match A LOT of patterns you might not want it to match. Make sure you test it and that it behaves how you expect it to. This will also match requests for files in subdirectories too (/foo/bar/something.html) and will pass that entire string to your page variable.

Good luck.
 
Back
Top