18117

get params with clean url in multi hosting environment

Question:

the website root contains three directories say a,b,c all acting as root for different domains

i created one .htaccess in directory b and added the following rules to it

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php RewriteRule ^([^/]*)/?([^/]*)/$ /b/sample-page?bbi=$1&bbl=$2 [L]

In place of last line above, i have also tried

RewriteRule ^b/([^/]*)/([^/]*)$ /b/sample-page?bbi=$1&bbl=$2 [QSA,L]

Using above rules

http://testsite.com/b/pageone.php is successfully rewritten as

http://testsite.com/b/pageone

But http://testsite.com/b/sample-page.php?bbi=value1&bbl=value2

is rewritten as http://testsite.com/b/sample-page?bbi=value1&bbl=value2 instead of

http://testsite.com/b/sample-page/value1/value2 or

http://testsite.com/sample-page/value1/value2

Answer1:

You need to add an L flag to your other rule:

RewriteRule ^(.*)$ $1.php [L]

To handle the other situation, you'll need to add a rule <strong>before</strong> that one.

RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} ^/b/([^/]+)/([^/]+)/([^/]+) RewriteCond %{DOCUMENT_ROOT}/b/%1.php -f RewriteRule ^/?([^/]+)/([^/]+)/([^/]+) $1.php?bbi=$2&bbl=$3 [L]

This should make it so when you go to http://testsite.com/b/sample-page/value1/value2, you get served the content at /b/sample-page.php?bbi=value1&bbl=value2

Recommend

  • Remove index.php from url after removing web folder from frontend and backend in yii2
  • url construction htaccess
  • .htaccess rewrite rule preventing infinite loop
  • URL Rewrite -.htaccess
  • Codeigniter 404 can't find index.php (only on real server, not on virtual server)
  • Redirect with form variable doesn't work properly
  • How to hide my .html and .php extensions using .htaccess?
  • getting 404 error when removing file extension worked on wamp but not working on lamp
  • Redirect internal to path, if resource doesn't exists
  • htaccess php_value auto_prepend_file gives me internal 500 error
  • how to rewrite HTTP get request with .htaccess
  • mod_rewrite in htaccess: best way to prevent looping?
  • How to pass a value from ASP.NET MVC controller to ASP.NET webforms control inside MVC View?
  • ASP.NET MVC 2 Preview 2 - display directory list rather than home/index
  • Jquery popup on mouse over of calendar control
  • Reading a file into a multidimensional array
  • Android application: how to use the camera and grab the image bytes?
  • Firefox Extension - Monitor refresh and change of tab
  • ADO and msqli connections very slow
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • htaccess add www if not subdomain, if subdomain remove www
  • CakePHP 2.0.4 - findBy magic methods with conditions
  • JSON response opens as a file, but I can't access it with JavaScript
  • How to clear text inside text field when radio button is select
  • Highlight one bar in a series in highcharts?
  • Scrapy recursive link crawler
  • DomPDF {PAGE_NUM} not on first page
  • How reduce the height of an mschart by breaking up the y-axis
  • Accessing IRQ description array within a module and displaying action names
  • javascript inside java/jsp code
  • Perl system calls when running as another user using sudo
  • htaccess rewriting URLs with multiple forward slashes
  • Display Images one by one with next and previous functionality
  • Upload files with Ajax and Jquery
  • Weird JavaScript statement, what does it mean?
  • Web-crawler for facebook in python
  • Do I've to free mysql result after storing it?
  • A cron job substitute?
  • json Serialization in asp
  • need help with bizarre java.net.HttpURLConnection behavior