Jump to content

[SOLVED] DANGER! newbie: url friendly howto at mod_rewrite


monkeynote

Recommended Posts

hello guys!

 

i would like to ask on how can i create my user url friendly at Windows XP, Apache 2.2 and PHP 5.2?

its something like this

eg.

http://sitename.com/login.php -> http://sitename.com/login/

http://sitename.com/redirect.php?accesscode=accesscode -> http://sitename.com/redirect/

http://sitename.com/control panel.php -> http://sitename.com/control panel/

 

how can i also link my stylesheet and images on it? should i put slash from the beginning of my image file?

eg.

"images/image.gif" -> "/images/image.gif"

"scripts/style.css" -> "/scripts/style.css"

 

i tried to place an .htaccess on the root website folder and mod_rewrite loaded according to <?php phpinfo();?> but it doesnt work :(

 

this is what i put in .htaccess file

Options -Indexes 
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([A-Za-z0-9-]+)/?$ /$

 

i tried to put http://sitename/test at my browser but the result is page cannot be found

 

i hope that you can help me with my problem guys :(

 

Link to comment
Share on other sites

thanks for the reply :)

 

i typed this in my .htaccess and restart Apache 2.2

Options -Indexes
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-_ ]+)/?$ $1.php

at first... it was not working when i type http://localhost:8888/test.php. it displays the normal page. but when i change Apache's httpd.conf file changing AllowOverride to ALL (default is NONE)

<Directory "D:\PHPDirectory">
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>

 

when i restart my apache... i get an internal server error! wah!!!!!!!!!!  :'( but when i put remarks on #RewriteRule ^([a-zA-Z0-9-_ ]+)/?$ $1.php it runs ok. Please help me with my problem :'(

Link to comment
Share on other sites

The Internal Server Error might be caused by not having mod rewrite module activate, wrong write rule or other problems..

Ok let's check on the mod rewrite module first, open up your http.conf

Look for

LoadModule rewrite_module modules/mod_rewrite.so

Make sure it's not comment out.

 

Now let's check for the rewrite rule, ok I think this causes the problem.

Change it to

RewriteRule ^([a-zA-Z0-9-_]+)/?$ $1.php

Link to comment
Share on other sites

wow! it works! hackerkts! you are indeed a hacker  8)

 

i have another question.... i created a page called testing.php but there are querystrings on it... how can i masked it like

from this

http://localhost:8080/testing.php?Name=monkeynote&Address=myaddress&remarks=cute

to this

http://localhost:8080/testing.php/monkeynote/myaddress/cute

testing.php

<?php 
echo $_GET["Name"] . "<br />";
echo $_GET["Address"] . "<br />";
echo $_GET["remarks"] . "<br />";
?>

promise it will be my last question :) thanks again! :)

 

Link to comment
Share on other sites

i got the solution to my problem (by using ^testing/^([a-zA-Z0-9-_]+)/^([a-zA-Z0-9-_]+)/^([a-zA-Z0-9-_]+))but there comes another problem...

 

how about the space from my URL for example i have an Add User.php... how can i change it into

http://localhost:8080/Add User/ i tried [:space:] but the URL appears like http://localhost:8080/Add%20User/  ???

 

also, im also having some problems with regards to redirection. for example... they are accessing the

          http://localhost:8080/controlpanel/

but the user is not authorized! so i redirect them to Unauthorized Page.php

 

what happen is that, Unauthorized Page.php will be added to http://localhost:8080/controlpanel/

          http://localhost:8080/controlpanel/Unauthorized Page.php

 

mod_rewrite is not easy as i thought it would be  ??? i hope that you can help me resolve this problem ???

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.