1

Okay, so I have a small webstore area and I have it set up so that every webstore is called with the '/webstore/?webstore=webstorename' I managed to have it so you can just type in 'www.domain.com/webstorename'. But for some reason, every page has '?webstore=pagename' trailing it. EG: 'www.domain.com/dash/?webstore=dash'

ErrorDocument 403 /errordocs/noaccess.php
ErrorDocument 404 /errordocs/notfound.php

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^([A-Za-z0-9]+)$ /webstore/index.php?webstore=$1

I'm not sure why it's causing this to happen, but I'm hoping it's a small fix. I'm happy to answer any questions you may have. Thanks.

  • 1
    do you mean that when you type `www.domain.com/webstorename` it redirects in the browser to the url `www.domain.com/webstore/?webstore=webstorename`? As in, it displays that URL in the location bar? And that what you want is that on the server level the url is rewritten to `www.domain.com/webstore/?webstore=webstorename` while remaining at `www.domain.com/webstorename` in the browser ? – Tularis Mar 17 '14 at 18:07
  • When I type the d.com/webstorename it works fine, but if I visit a page that isn't a webstore I get the d.com/dash/?webstore=dash even though, 'dash' isn't saved anywhere as a webstore – DracoMalfoy Mar 17 '14 at 18:14
  • Is there a finite number of webstore names? – gtr1971 Mar 17 '14 at 18:19
  • webstore names can only be used once, but other than that, they're infinite – DracoMalfoy Mar 17 '14 at 18:21

1 Answers1

0

This question was asked here: .htaccess rewrite query string as path

You should place your "webstore" in a path and then test for that:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?store/(.*?)$ /index.php?webstore=$1 [L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?webstore=([^\&\ ]+)
RewriteRule ^/?index\.php$ /store/%1 [L,R=301]
Community
  • 1
  • 1
gtr1971
  • 2,672
  • 2
  • 18
  • 23
  • This worked, but is there a way I can have two rewrite rules? one for the actual store, and one for the categories within the store? – DracoMalfoy Mar 17 '14 at 18:50
  • And I still get the "dashboard/?webstore=dashboard" problem – DracoMalfoy Mar 17 '14 at 18:53
  • Are you getting a 404 response? – gtr1971 Mar 17 '14 at 19:29
  • nope, it takes me to the dashboard page, it just has the ?webstore... trailing on the end – DracoMalfoy Mar 17 '14 at 19:31
  • My answer assumes you have a request like `http://www.domain.com/store/coolshirts/`. It's testing the path for the word "store" in the first subdirectory of the pathname. So if you type in `http://www.domain.com/dashboard/` it shouldn't be a problem. What's the filetype serving the page? – gtr1971 Mar 17 '14 at 19:41
  • all of the pages on this website are php. And, yeah I am using the /store/storename. – DracoMalfoy Mar 17 '14 at 19:45
  • Is this entirely database driven? Are ALL of your pages being served as a parameter off of the index page? – gtr1971 Mar 17 '14 at 19:52
  • the majority of them are linked to the database for getting usernames, storenames and such. But, all files are in seperate directories excluding the homepage, the webstore and the categories page. The webstore and categories are both get pages – DracoMalfoy Mar 17 '14 at 20:04
  • ALSO, it doesn't always do it. Only sometimes, which is odd. – DracoMalfoy Mar 17 '14 at 20:05
  • it actually stopped doing it now. – DracoMalfoy Mar 17 '14 at 20:42