Forum Moderators: phranque
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.
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
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-
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...]
# 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.
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
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?
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?