1

I know this question has been asked and answered many times, but my experience of .htaccess, regualr expressions, mod rewrites etc.. have normally drove me crazy.

I see on most websites the structure of the url is in a directory-like structure, wwww.linku.biz/edit. My ultimate question is how do you do this?

Are all these sites behind the scenes have normal URL variables but just re-wrote? such as www.linku.biz/myprofile?edit="whatever" , is this all done with .htaccess, and mod_rewrites?

  • I want to type in my url www.linku.biz/search however its actually www.linku.biz/search.php

  • I want to type in my url www.linku.biz/JackTrow however its actually www.linku.biz/profile.php?us="JackTrow

  • Also I want data re-wrote when I have lots of URL data, such as www.linku.biz/search?a=1&b=2&c=3 actually beeing www.linku.biz/search.php?a=1&b=2&c=3

Niket Malik
  • 1,075
  • 1
  • 14
  • 23
Jack Trowbridge
  • 3,175
  • 9
  • 32
  • 56
  • Yes, look at the [mod-rewrite tag wiki](http://stackoverflow.com/tags/mod-rewrite/info) or the [Apache manual on that](http://httpd.apache.org/docs/2.0/misc/rewriteguide.html). Tell what you've tried. – mario Sep 01 '13 at 00:53
  • possible duplicate of [hide .php extension - htaccess](http://stackoverflow.com/questions/8371634/hide-php-extension-htaccess) – mario Sep 01 '13 at 00:53
  • possible duplicate of [How do I achieve a url like www.example.com/username to redirect to www.example.com/user/profile.php?uid=10?](http://stackoverflow.com/q/9873641) or [MOD\_REWRITE HELP!](http://stackoverflow.com/q/2790463) or [PHP Mod rewrite for user accounts](http://stackoverflow.com/q/17386622) – mario Sep 01 '13 at 00:54

2 Answers2

1

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search\.php\[?^\s] [NC]
RewriteRule ^ search? [R=301,L]

RewriteRule ^search/?$ search.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ profile.php?us=$1 [QSA,L]

Please note that your requirement 1 & 3 will both be covered by rule # 1

Prix
  • 19,417
  • 15
  • 73
  • 132
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

Add this rules to your .htaccess file in Root folder :

To do this www.linku.biz/JackTrow <--- www.linku.biz/profile.php?us="JackTrow

 RewriteRule ^profile.php?us=(.*)$ /$1 [R=301,L]

To do this : www.linku.biz/search however <--- www.linku.biz/search.php

 RewriteRule ^(.*).php$ /$1 [R=301,L]

Your last one , i have not understood what you want exactly.

Charaf JRA
  • 8,249
  • 1
  • 34
  • 44