TecTao Posted May 26, 2014 Share Posted May 26, 2014 About a year ago I wrote a mod_rewrite in at sites htaccess file. It was to call a page that queried the database based on a unite code that was assigned to a member. If the member was assigned a code that was FL1001, the URL www.marketingteammates.com/FL1001 would bring up a page that quaried that member and displayed their database content. In the users table of the site, it quaried the field webPageID and the information was called. It called a page webpage.php that quaried the info. The URL in the address bar still displayed www.marketingteammates.com/FL1001. Here are the lines of code in the htaccess file. RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([A-Za-z])([A-Za-z])([0-9]+)$ /webpage.php?webPageID=$1$2$3 [NC,L] I now have a second page completely different from the webpage.php. It is a page storeNumber.php and would query a field storeNumberID. This field could contain any kind of string such as Store#101, or mystore101, or #101 is my store. I tried using the same rewite rule just replaceing the webpage.php and variable with storeNumber.php and $storeNumberID. This doesn't work. It also leads me to wonder if there can even be two different pages in the mod_rewrite. How would it diferentiate one from the other. Thanks for any help in advance. Mike Quote Link to comment https://forums.phpfreaks.com/topic/288791-problem-with-second-web-page-content-using-htaccess-page-mod_rewrite/ Share on other sites More sharing options...
Ch0cu3r Posted May 26, 2014 Share Posted May 26, 2014 It also leads me to wonder if there can even be two different pages in the mod_rewrite. How would it diferentiate one from the other. You can have as many rewriterules as you like. The problem is each one needs to differentiate from each other. To do so you need add something in the url to differentiate the two types of urls, such as for stores have urls like site.com/store/store-id# RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^store/([a-z0-9-]+)$ /store.php?storeID=$1 [NC,L] # rule for stores RewriteRule ^([A-Za-z])([A-Za-z])([0-9]+)$ /webpage.php?webPageID=$1$2$3 [NC,L] # rule for member webpage This field could contain any kind of string such as Store#101, or mystore101, or #101 is my store. You will have problems having the # in the url as anything after it is not sent in the request to the server. Quote Link to comment https://forums.phpfreaks.com/topic/288791-problem-with-second-web-page-content-using-htaccess-page-mod_rewrite/#findComment-1480941 Share on other sites More sharing options...
TecTao Posted May 26, 2014 Author Share Posted May 26, 2014 Thanks ChOcu3r, That works perfect. I had tried a number of different combinations of that but couldn't get it to fly. Can the string be defined to contain spaces between words? Again thanks for your prompt response back. mike Quote Link to comment https://forums.phpfreaks.com/topic/288791-problem-with-second-web-page-content-using-htaccess-page-mod_rewrite/#findComment-1480969 Share on other sites More sharing options...
Ch0cu3r Posted May 27, 2014 Share Posted May 27, 2014 Spaces can be used but they will most likely end up being encoded to %20, which is just ugly, an alternative would be to convert all spaces to underscores. This will have to be done in your PHP code before the link is made, example $storeName = 'New Look'; $storeLink = '/store/' . str_replace(' ', '_', $storeName); // converts spaces to underscores in the store name echo '<a href="'.$storeLink.'">'.$storeName.'</a>'; For the rewriteRule to match you need to include an underscore in the pattern ^store/([a-z0-9_]+)$ Quote Link to comment https://forums.phpfreaks.com/topic/288791-problem-with-second-web-page-content-using-htaccess-page-mod_rewrite/#findComment-1481055 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.