Jump to content

Problem with Second Web Page content using .htaccess Page Mod_rewrite


TecTao

Recommended Posts

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

Link to comment
Share on other sites

 

 

 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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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_]+)$

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.