0

I need to dynimicaly rewrite urls & query string using htaccess

eg i may enter this url in browser eg : http://somename.com/testpage

Actuly the page testpage dose not exist in my server this should be routed to index.php for that i use the below rewrite rule

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /news/

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /news/index.php [L]
</IfModule>

and i also need to rewrite query string dynamically

Eg : http://somename.com/news/testpage/?user=100 to http://somename.com/news/testpage/user/100

Or http://somename.com/news/testpage/?user=100&listtype=ul to http://somename.com/news/testpage/user/100/listtype/ul

when i use var_dump($_REQUEST); in php its showing the url rewrite with query string value for eg url as http://somename.in/news/mygetst/?user=100 in which there is no folder / file in the name of mygetst and the url got rewrited as http://somname.in/news/mygetst/user/1000/ i should not get array(1) { ["mygetst"]=> string(4) "user" } the key mygetst is a page rewrite not query-string

Varun Sridharan
  • 1,983
  • 2
  • 20
  • 54
  • That's a great duplicate of your [question from yesterday](http://stackoverflow.com/q/24337391/) on which we worked for hours and you are failing to respond with basic information. Once again: do we even know that mod_rewrite is enabled on your server? Is even one file redirecting properly? Let's start from there. – zx81 Jun 22 '14 at 10:04
  • @zx81 mod_rewrite is enabled in my server but my requirement is not fullfilled so i asked anubhava how this can be done he told me to create a new question with exact requirement he told me to i created a new question with my exact requirement – Varun Sridharan Jun 22 '14 at 10:08
  • Okay, you say "it's enabled." But how do you know that it's enabled? Is even one file redirecting properly? Let's start from there. – zx81 Jun 22 '14 at 10:14
  • @zx81 if i use this `RewriteEngine On RewriteBase /news/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /news/index.php [L]` its working even any other type of mod_rewrite script is working but the script which is answered is not working for me i dont know what to do – Varun Sridharan Jun 22 '14 at 11:26
  • One last thought: maybe try anubhava's rules from last time except the last rule `RewriteRule "^([^/]+)/([^/]*)(?:/(.*))?$" $3?$1=$2 [L,QSA]` which for some reason is not working on my server. All the other rules are working for me. Good luck, I realize it's a frustrating problem for you. Leaving the computer now, bye. – zx81 Jun 22 '14 at 12:16
  • I got back to this thread a few minutes back and merged requirements from your previous question and this one First of all please be very clear on what you want. I think you want a URL like `http://somename.com/news/testpage/user/100` instead of `http://somename.com/testpage/user/100` isn't that true? – anubhava Jun 22 '14 at 13:38
  • You are again back to your cryptic comments habits. I have told you more than once these useless comments are not helpful. If you want help spend time in explaining your problem clearly. Did you not write in previous question that: `i may either load the url like this http://varunsridharan.in/news/mygetst/?user=100 or http://varunsridharan.in/news/?user=100 or http://varunsridharan.in/news/mygetst/?user=100&page=20&start=a` All those URLs are starting with `/news/` and here `/news/` is missing from your URL. – anubhava Jun 22 '14 at 14:13
  • @anubhava i am sorry that was my mistake all my url will look like this only `http://varunsridharan.in/news/` and then the page rewrite and querystring rewrite will need to go `http://varunsridharan.in/news/testpage/?user=10` to `http://varunsridharan.in/news/testpage/user/10` – Varun Sridharan Jun 22 '14 at 14:32
  • Ok will it always be `/news/testpage` OR can it be `/news/anypage` OR `/news/anotherpage` etc etc? – anubhava Jun 22 '14 at 14:35
  • @anubhava after `/news/` the string will be dynimic – Varun Sridharan Jun 22 '14 at 14:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/56066/discussion-between-s-varun-and-anubhava). – Varun Sridharan Jun 22 '14 at 14:40

0 Answers0