Forum Moderators: phranque
I am having a bit of a problem with mod_rewrite. Being a beginner I don't quite know what I am doing wrong. I want to rewrite files like this:
original url:
[domain.com...]
this I want to go to:
[domain.com...]
This is what I tried:
RewriteEngine on
Options +FollowSymLinks
RewriteRule ^(.*?)directory(.*)$ $1goto.php?information=$2 [L]
I keep getting a 403 message, what am I doing wrong?
All the best,
Vincent
Welcome to WebmasterWorld [webmasterworld.com].
It may be helpful to see what your logs are showing.
For now, I'm assuming that all the .html files are in /directory1/ and that goto.php is in /directory2/, because I'm not quite sure what you want to do.
RewriteEngine on
RewriteCond %{REQUEST_URI} /directory1/(.*)\.html$
RewriteRule .* /directory2/goto.php?information=%1.html [L]
What the code does: If a user requests a .html file, serve goto.php with information set to the filename with extension.
original url:
[domain.com...]this I want to go to:
[domain.com...]The Options +FollowSymLinks directive must precede the RewriteEngine directive, but you may not need the Options directive at all.
The domain name is not "visible" to RewriteRule.
Quantifier "?" should not directly follow quantifier "*"Try something like this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !goto\.php$
RewriteRule ^(.+)/([^/]+)$ /$1/goto.php?information=$2 [L]
Jim
"403 Forbidden
You don't have permission to access /recensioner/saxon.html on this server."
Could this have something to do with the server where the website is hosted?
All the best,
Vincent
I do not really get what you mean with "file space" and "web space" but what I wrote above refers to the actual url.
I wrote to my webhost and they told me that my rewriting rules may interfere with those of the server...
Let's say you have a widget sales site. Looking at it from the web and from FTP or Telnet, we see two different views, but they are the same:
Web space: [yourdomain.com...]
File space: users/vineld/public_html/production/widgets/cart.php?pid=001
In this case, the URL is straightforward, but your mod_rewrite is used to do two things: First, to serve all files from a subdirectory called "production," and second to "convert" php files to html pages so that users and SE spiders see "static" pages, and not the script.
The "Web space" and "file space" are mapped to each other, but differ in naming methods. The server's user subdirectory, your username, and directory "public_html" are not visible to HTTP users on the Web, and HTTP users also don't see that you really have two main subdirectories - One for production and one for testing purposes. The only overlap is in the "widgets" directory. But yet the two spaces mean the same thing -- they refer to the same resource, a page about widget product number 001.
mod_rewrite lives at a place in the server where it is part of both the Web space world and the server filesystem world. A common cause of problems and confusion is mixing up the ways the two worlds refer to the same file. So, my question was whether you recognized the subdirectory path, and whether you expected the server to try to access that subdirectory path. If not, then you will probably need to use mod_rewrite's RewriteBase directive to tell mod_rewrite where to start in your filesystem to do the redirects correctly.
Jim