homepage Welcome to WebmasterWorld Guest from 54.205.189.156
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
mod_rewrite problems
trying to use simple rewriting rules
vineld




msg:1520438
 8:52 pm on Aug 27, 2003 (gmt 0)

Hello,

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

 

closed




msg:1520439
 4:07 pm on Aug 28, 2003 (gmt 0)

vineld,

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.

jdMorgan




msg:1520440
 5:58 pm on Aug 28, 2003 (gmt 0)

vineld,

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

vineld




msg:1520441
 11:02 am on Sep 18, 2003 (gmt 0)

Thanks to both of you for trying to help me out. I have tried both versions that you suggested but none of them seem to work. I keep getting this:

"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

vineld




msg:1520442
 11:11 am on Sep 18, 2003 (gmt 0)

The same also happens when I try to request the php file directly when the .htaccess file is in the same directory...

jdMorgan




msg:1520443
 2:52 pm on Sep 18, 2003 (gmt 0)

vineld,

Do you recognize the words recession/saxon in that error message? If they are part of your server file space (and not necessarily your server *web* space), you may have other .htaccess rules that are interfering, or you may need to use the RewriteBase directive to straighten things out.

Jim

vineld




msg:1520444
 11:05 pm on Sep 23, 2003 (gmt 0)

Oh, sorry, maybe I should have left out the actual file names. The request "recension/saxon.html" is supposed to be sent over to goto.php or whatever the file is called.

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...

jdMorgan




msg:1520445
 11:52 pm on Sep 23, 2003 (gmt 0)

vineld,

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved