Hello,

i'm working on a script and I want to make the links such as www.mysite.com/signup. this link for registration

www.mysite.com/user/username and this link for user's profile. the links without any extention

how can I do that?

swati.ramnani commented: matrimony +0

You would use "pretty urls" with mod-rewrite. Add an htacess file to your root directory with the rewrites in there
You can search online for auto gens to create your file or re-write. I wont post a link because it seems they add rewrite spam. but below should work for signup

RewriteRule ^signup$ /signup.php [L]

Make sure mod-rewrite is on with your server and it is NOT on by default in WAMP

Member Avatar for diafol

You want a redirect or a rewrite. They're different.

I want the both :)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site/inner.php?page=$1 [L]
</IfModule>

1;First you create a page inner.php

2;Set htacess with above code

3;Set inner.php

<?php
$page= (isset($_REQUEST['page']) || $_REQUEST['page'] != "")? $_REQUEST['page'] : "index";
include_once($page.".php");
?>

**NB: the resquested page name should be same as your file name **

eg: www.yoursite.com/register , there should be a file with file name register.php

ok good.

what if I want to be profile likns such as

www.mysite.com/profile/usernamehere

I have tried to modify the code above to do so but I couldn't

ok it works now :)

thank you

my htaccess

Options +FollowSymLinks

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /adver/profile.php?username=$1

RewriteRule ^index$ index.php [L]
RewriteRule ^newuser$ newuser.php [L]
RewriteRule ^newsite$ newsite.php [L]
RewriteRule ^newadver$ newadver.php [L]
RewriteRule ^signout$ signout.php [L]
RewriteRule ^signin$ signin.php [L]
RewriteRule ^profile$ profile.php [L]

it works but when I enter for example

www.mysite.com/profile/a. all links will be under profile

example to singout: www.mysite.com/profle/signout

it souhld be www.mysite.com/signout

how to solve that?

any help please?

Hi

RewriteRule ^index$ index.php [L]
RewriteRule ^newuser$ newuser.php [L]
RewriteRule ^newsite$ newsite.php [L]
RewriteRule ^newadver$ newadver.php [L]
RewriteRule ^signout$ signout.php [L]
RewriteRule ^signin$ signin.php [L]
RewriteRule ^profile$ profile.php [L]

No need to add this in your htaccess file

For signout give url like ***www.mysite.com/signout ***
And for other links use following URL's

  • www.mysite.com/newuser
  • www.mysite.com/newadver
  • www.mysite.com/signin etc...

ok;

change the htaccess like this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)-(.*)$ /site/profile.php?page=$1&id=$2 [L]

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site/profile.php?page=$1 [L]
</IfModule>

then in profile.php

    <?php

    if(isset($_REQUEST['page']) && $_REQUEST['page']=="profle") {
    $page= (isset($_REQUEST['id']) || $_REQUEST['id'] != "")? $_REQUEST['id'] : "index";
    include_once($page.".php");

    }

    ?>

And set url like

www.mysite.com/profle-signout

I tried your both answers but in one time shows me this error

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

localhost
Apache/2.4.2 (Win32) OpenSSL/1.0.1c PHP/5.4.4

the other one works but with same links error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.