1

I tried lot of combinations using available examples (.htaccess directives), but I couldn't able to achieve what I want. The problem is...

My actual URL is http://localhost/smon2/custsms/index.php?p_mob=9886419001

What I want is http://localhost/smon2/custsms/

Please help me in wrinting .htaccess code lines. Thanks

I tried with few of the items below...

RewriteEngine On  
RewriteCond %{QUERY_STRING} ^p_mob=1$
RewriteRule (.*) $1? [R=permanent]

RewriteEngine On  
RewriteCond %{QUERY_STRING} "p_mob=" [NC]
RewriteRule (.*)  /$1? [R=301,L]

RewriteEngine On  
RewriteRule ^/custsms/%{QUERY_STRING}/?$  http : //localhost/smon2/custsms/ [NC,L]

Nothing was working. please help.

5
  • @anubhava added the code in the question itself. the comment section formating the into unreadable block. Commented Oct 8, 2015 at 8:50
  • Can you clarify what you are trying to achieve here - why not simply use the URL http://localhost/smon2/custsms/? Commented Oct 8, 2015 at 8:52
  • ok good, where is this .htaccess located? Is it under /smon2/ directory? Commented Oct 8, 2015 at 8:52
  • yes it is located in smon2 directory. Commented Oct 8, 2015 at 8:53
  • My objective is, any mobile number pass to this page will open a form, based on $_REQUEST['p_mob'], this should happen only once. when I submit the form the URL should not contain the parameter, so that form opening event will not occur. Commented Oct 8, 2015 at 8:56

1 Answer 1

1

Replace all your current rules with this rule:

DirectoryIndex index.php
RewriteEngine On
RewriteBase /smon2/

RewriteCond %{QUERY_STRING} ^p_mob=\d+ [NC]
RewriteRule ^(custsms)/index\.php$ $1/? [R=301,L,NC]
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks @anubhava, now I get error object not found as the URL turn into localhost/custsms
this url works fine as expected but when I enter localhost/smon2/custsms/index.php?p_mob=9886419001 it turns to localhost/custsms. Since there is no such file/directory getting 404 error.
Ah fixed it now. Try my updated rule after clearing your browser cache.
Cool. it works. but my $_REQUEST is empty now. is it possible to catch th p_mob value in some variable to further process in php?
No, once URL has been redirected to this one without any query parameter you cannot retrieve p_mob back.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.