0

I'm using the following htaccess code.

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    RewriteRule ^Profile/([0-9]+)/?$ ViewProfile.php?id=$1 [NC,L]

This is the url http://localhost/ConnectMyProfile/ViewProfile.php?id=CMP26944

I need to convert this url to http://localhost/ConnectMyProfile/ViewProfile/CMP26944

For that i used this code (RewriteRule ^Profile/([0-9]+)/?$ ViewProfile.php?id=$1 [NC,L]).

It's not working.Please help me to fix this.

user3667960
  • 115
  • 1
  • 1
  • 8

1 Answers1

1

for start mod-rewire start from the your domain. then on localhost if you want your mod_rewrite work you should pass it to your project address,
before all above thing, you should check your mode_Rewire be enable
redirect:
http://localhost/ConnectMyProfile/ViewProfile.php?id=CMP26944 or
http://localhost/ConnectMyProfile/ViewProfile?id=CMP26944
to
http://localhost/ConnectMyProfile/ViewProfile/CMP26944

RewriteEngine On
RewriteBase /ConnectMyProfile/


# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /ViewProfile\.php\?id=([^\s&]+) [NC]
RewriteRule ^ ViewProfile/%1? [R=302,L]

RewriteCond %{THE_REQUEST} /ViewProfile\?id=([^\s&]+) [NC]
RewriteRule ^ ViewProfile/%1? [R=302,L]


# internally rewrites /ViewProfile/ABC123 to ViewProfile.php?id=ABC123
RewriteRule ^ViewProfile/([A-Z,0-9]+)$ ViewProfile.php?id=$1 [L,NC,QSA]

# PHP hiding rule
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
Shayan
  • 956
  • 9
  • 20
  • i'm getting same url (http://localhost/ConnectMyProfile/ViewProfile?id=CMP26944). Not changing – user3667960 Mar 14 '16 at 06:33
  • @user3667960, do you enable `mod_rewrite` on your system? – Shayan Mar 14 '16 at 06:34
  • yes. (it's removing .php from the file. but the url is not changing) – user3667960 Mar 14 '16 at 06:36
  • @user3667960 yeah, sorry, i fix my answer and it works fine now – Shayan Mar 14 '16 at 06:42
  • Hi bro.Sorry i'm not getting it.I'm clicking on this url http://localhost/ConnectMyProfile/ViewProfile?id=CMP26944.But this is not converting into http://localhost/ConnectMyProfile/ViewProfile/CMP26944.If i used http://localhost/ConnectMyProfile/ViewProfile.php?id=CMP26944 like this it is redirecting to http://localhost//ViewProfile.php – user3667960 Mar 14 '16 at 07:15
  • @user3667960 on your question you want to rediretc " http://localhost/ConnectMyProfile/ViewProfile.php?id=CMP26944 " to " http://localhost/ConnectMyProfile/ViewProfile/CMP26944 " ( url has ViewProfile.php ). am i wrong? – Shayan Mar 14 '16 at 07:20
  • If i manually type this url (http://localhost/ConnectMyProfile/ViewProfile/CMP26944) i'm getting the page content. But if i clicked this link (localhost/ConnectMyProfile/ViewProfile?id=CMP26944) it is not converting to this one (http://localhost/ConnectMyProfile/ViewProfile/CMP26944) – user3667960 Mar 14 '16 at 07:20
  • when i click on this url localhost/ConnectMyProfile/ViewProfile?id=CMP26944 it will go to ViewProfile.php and there i get the id and display the details.But after clicking on that url it should be displayed as localhost/ConnectMyProfile/ViewProfile/CMP26944. – user3667960 Mar 14 '16 at 07:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/106192/discussion-between-shayanypn-and-user3667960). – Shayan Mar 14 '16 at 07:26
  • hi bro. i uploaded the code in domain with same htaccess. it is taking to the followinr url - http://www.connectmyprofile.com/ConnectMyProfile/ViewProfile/CMP26944 – user3667960 Mar 21 '16 at 12:34
  • @user3667960 does file ViewProfile.php exist on the directory? i mean does this htaccess code work on localhost and does not work on the server your? – Shayan Mar 21 '16 at 16:26
  • yes.. it is working fine in localhost. but not working in server. ViewProfile.php file exists on server. – user3667960 Mar 22 '16 at 04:50
  • @user3667960 maybe mode_rewrite on enable on your server please follow [this](http://stackoverflow.com/a/35726774/3828573) for enabling apache mode_rewrite – Shayan Mar 22 '16 at 09:03
  • need to change this ( RewriteBase /ConnectMyProfile/ ) in server ??? – user3667960 Mar 22 '16 at 09:22
  • @user3667960 if you domain is "test.com/ConnectMyProfile/" , yes. – Shayan Mar 26 '16 at 14:17
  • URL show as i want but on page showing Error: 500 Internal Server Error. how to resolve. I use above .htaccess code – Inderjeet Jan 17 '18 at 09:01
  • Now i found if my url view.php?url=home it will work if i have view.php?url=mapsko-casa-baella this will not work – Inderjeet Jan 17 '18 at 10:30
  • i have url like abc-delhi-india etc not working – Inderjeet Jan 17 '18 at 10:53