Jump to content
  • Advertisement
Sign in to follow this  
Thevenin

[web] mod_rewrite difficulties.

This topic is 4500 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I had this figured out a long whiles ago, but I completely forget how to do it. I'm trying to mod_rewrite the following via Apache's mod_rewrite mod. (Without showing the changes in the client's URL bar)
http://127.0.0.1 to become
   http://127.0.0.1/cgi-bin/Fleurin.cgi?P=Home

http://127.0.0.1/Forum to become
   http://127.0.0.1/cgi-bin/Fleurin.cgi?P=Forum


http://127.0.0.1/Forum/3 to become
   http://127.0.0.1/cgi-bin/Fleurin.cgi?P=Thread&T=3
All I can come up with so far is this..
RewriteEngine on
RewriteRule ^/News /cgi-bin/Fleurin.cgi?P=News [nc]
... which doesn't work at all. =/ [Edited by - Thevenin on April 20, 2006 3:40:23 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
RewriteRule ^news$ cgi-bin/Fleurin.cgi?P=News [NC,L]

Share this post


Link to post
Share on other sites
I've tried a bunch of combinations now, and the only one that works is providing the full URL (http://127.0.0.1/cgi-bin/Fleurin.cgi?P=) for the redirection.

eg...


Doesn't Work
RewriteRule ^news$ cgi-bin/Fleurin.cgi?P=News [NC,L]

Works
RewriteRule ^/news$ http://127.0.0.1/cgi-bin/Fleurin.cgi?P=News [NC,L]

Any ideas?

Share this post


Link to post
Share on other sites
Sorry, I assumed that you were using .htaccess for the directives (which you should, for ease of portability).

Redirections within the server configuration file require that paths be absolute. Directory configuration, on the other hand, allows relative paths.

As a side note, I'd only glanced over your first post. What you're trying to do (encapsulate all URL requests) is extremely difficult to manage. Optimally, instead of hiding the user request from the script, it should be supporting its own URL format specification (as it is currently, but with the ugly URLs).

Nevertheless, it is possible to implement a limited redirect sequence.

RewriteEngine on

RewriteRule ^/forum/(.*)$ /cgi-bin/Fleurin.cgi?P=Thread&T=$1 [QSA,NC]
# Should be caught in the dispatcher (change the last rule's plus sign to an asterisk).
RewriteRule ^/$ /cgi-bin/Fleurin.cgi?P=Home
# Rather than explicitly setting each requestable page, allow the script to determine the request validity.
RewriteRule ^/([^.]+)$ /cgi-bin/Fleurin.cgi?P=$1 [QSA,L]

Share this post


Link to post
Share on other sites
This is much less ugly. Hopefully it works.

RewriteEngine on

RewriteRule ^/cgi-bin/Fleurin.cgi/$ /cgi-bin/Fleurin.cgi?P=Home
RewriteRule ^/cgi-bin/Fleurin.cgi/forum/(.*)$ /cgi-bin/Fleurin.cgi?P=Thread&T=$1 [QSA,NC]
RewriteRule ^/cgi-bin/Fleurin.cgi/(.*)$ /cgi-bin/Fleurin.cgi?P=$1 [QSA]

RewriteRule ^/([^.]*)$ /cgi-bin/Fleurin.cgi/$1 [N,QSA,L]

Share this post


Link to post
Share on other sites
Adhering to your advice (somewhat), I...

  • Configured my apache conf to 'AllowOverride All'
  • Created a file in my htdocs directory called ".htaccess", inside it contains...

    Quote:
    RewriteEngine on

    RewriteRule ^/([^.]*)$ /cgi-bin/Fleurin.cgi/$1 [N,QSA,L]


  • I browsed to my cgi-bin folder and added the file ".htaccess" to it, inside this file contains...

    Quote:

    RewriteEngine on

    RewriteRule ^/cgi-bin/Fleurin.cgi/$ /cgi-bin/Fleurin.cgi?P=Home
    RewriteRule ^/cgi-bin/Fleurin.cgi/forum/(.*)$ /cgi-bin/Fleurin.cgi?P=Thread&T=$1 [QSA,NC]
    RewriteRule ^/cgi-bin/Fleurin.cgi/(.*)$ /cgi-bin/Fleurin.cgi?P=$1 [QSA]


  • Restarted Apache, browsed to "127.0.0.1/home", and got "The requested URL /home was not found on this server.".

    Share this post


    Link to post
    Share on other sites
    Heck even putting this..

    Quote:
    RewriteRule ^(.*)$ http://127.0.0.1/cgi-bin/Fleurin.cgi?P=News [L]


    In my htdocs (My home directory) doesn't even work. Am I missing the bigger picture?

    Share this post


    Link to post
    Share on other sites
    Are .htaccess files allowed in your apache? Some apache packages ship with .htaccess functionality turned off. Also, on windows servers it's usually htaccess (without the .)

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by Sander
    Are .htaccess files allowed in your apache? Some apache packages ship with .htaccess functionality turned off.


    Apache 2.0.55(Win32); downloaded from their homepage.

    Quote:
    Original post by Sander
    Also, on windows servers it's usually htaccess (without the .)


    AccessFileName .htaccess

    Share this post


    Link to post
    Share on other sites
    Sign in to follow this  

    • Advertisement
    ×

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    We are the game development community.

    Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

    Sign me up!