homepage Welcome to WebmasterWorld Guest from 54.205.122.62
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Help with url rewrite
dawlish

10+ Year Member



 
Msg#: 93 posted 12:18 am on Jan 8, 2003 (gmt 0)

I have a perl script on one of my sites but want to rewrite the url.

At present the url takes the following structure:

[domain.com...]

However I want it to be rewritten to the following:

[domain.com...]

I have other scripts on the site but only want to rewrite for this particular script.

Could you tell me whether this is possible and want I need to enter into the server config file. I believe that rewriting the url is possible with an apache mod but I'm not that knowledgeable about server issues. Any help most appreciated.

 

jdMorgan

WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 93 posted 1:06 am on Jan 8, 2003 (gmt 0)

dawlish,

This Introduction to mod_rewrite [webmasterworld.com] may be useful to you. However, why would you want to rewrite a long URL to a short one? Bearing in mind that the rewrite acts between the browser'r request and the server returning a file (or running a script), the more usual case is to rewrite a short URL to a long one. In this way, the user-supplied URL or on-page spiderable link is short, and is rewritten on request for use in accessing your page or script.

You can do it either way, just trying to clarify the goal here.

HTH,
Jim

amznVibe

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 93 posted 1:28 am on Jan 8, 2003 (gmt 0)

You are probably trying to make a virtual page look like a physical page?
But wouldn't this cause some problems if the user bookmarks that final url?
Or is this for like a search engine that finds a page listing in a database
and then you want to return the real page directly without a click?

I'd like to do something similar when people come into a site without the framed menu,
and then I route them into the menu with the current page (leaves a messy URL).
I guess I will have to pick up the mod_rewrite manual myself. -aV-

Robert Charlton

WebmasterWorld Administrator robert_charlton us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 93 posted 7:20 am on Jan 8, 2003 (gmt 0)

Here are two threads that I've bookmarked:

How to get rid of? in URL
Eliminating allergic symbols
[webmasterworld.com...]

CGI urls without "?"s, but also with no extensions
How do search engines see these?
[webmasterworld.com...]

jeremagne

10+ Year Member



 
Msg#: 93 posted 3:04 pm on Jan 8, 2003 (gmt 0)

With mod_rewrite you can do this by placing the following in an .htaccess or the httpd.conf file:

# To make it so that users can type in 319016.htm and the
# server returns script.pl?action=form&fid=319016 you can
# do this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule "^/([0-9]+)\.htm$" [domain.com...] [P]
</IfModule>

# Which basically says to remember the ID number (in $1)
# and retrieve the other URL instead. The [P] at the end
# says to do this all in proxy mode; without it Apache
# would redirect the browser to the other URL.

# To go the other way -- users have to type in the long
# version and the server retrieves the short URL (?!), you
# could do this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule "script\.pl\?.*fid=([0-9]+)" [domain.com...] [P]
</IfModule>

The mod_proxy module is required if you want to use this proxying feature. Otherwise the browser will get redirected to the new URL.

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 93 posted 3:14 pm on Jan 8, 2003 (gmt 0)

Welcome to WebmasterWorld [webmasterworld.com] jeremagne.

Be sure to read Marcia`s WebmasterWorld Welcome and Guide to the Basics [webmasterworld.com] post.

The [P] flag is not required to prevent the server from doing an external redirect. An external self redirect is only done when you explicitly use the [R] flag. Otherwise the server will just return the resource pointed to by the rewritten URI.

[httpd.apache.org...]

There is a big difference between an external redirect, an internal rewrite and a proxy request.

Andreas

dawlish

10+ Year Member



 
Msg#: 93 posted 9:56 am on Jan 9, 2003 (gmt 0)

Thanks for your advice.

I have the following in my conf file contained within a virtual statement as I have a few sites on this server.

LoadModule rewrite_module modules/mod_rewrite.so

<Virtual>
ServerName www..domain.com
ServerAdmin webmaster@domain.com
DocumentRoot /usr/local/etc/httpd/vhosts/www.domain.com/htdocs
ScriptAlias /cgi-bin/ /usr/local/etc/httpd/vhosts/www.domain.com/cgi-bin/

RewriteEngine On
RewriteRule "^/([0-9]+)\.htm$" [domain.com...]

</VirtualHost>

However when i go to www.domain.com/123.htm as an example I get a 404.

I want [domain.com...]

to be rewritten to
[domain.com...]

I don't want this to be apparent to the browser, spiders etc

What am I doing wrong?

andreasfriedrich

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 93 posted 2:50 pm on Jan 9, 2003 (gmt 0)

Check the RewriteLog file [httpd.apache.org] and your serverīs error log file.

Andreas

dawlish

10+ Year Member



 
Msg#: 93 posted 4:07 pm on Jan 13, 2003 (gmt 0)

Thanks for your advice.

I have now checked the error messages and it appears as though the problem has to do with the cgi-bin not being in the htdocs folder.

The error i get is a 404

is /usr/local/etc/httpd/vhosts/www.domain.com/htdocs/cgi-bin/ not found

But the cgi-bin is at this level /usr/local/etc/httpd/vhosts/www.domain.com/cgi-bin/

I have the following in my conf file contained within a virtual statement as I have a few sites on this server.

LoadModule rewrite_module modules/mod_rewrite.so

<Virtual>
ServerName www..domain.com
ServerAdmin webmaster@domain.com
DocumentRoot /usr/local/etc/httpd/vhosts/www.domain.com/htdocs
ScriptAlias /cgi-bin/ /usr/local/etc/httpd/vhosts/www.domain.com/cgi-bin/

RewriteEngine On
RewriteRule "^/([0-9]+)\.htm$" [domain.com...]

</VirtualHost>

Can anyone see what I'm doing wrong?

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