PHP.htaccess problem, specific / dynamic keywords

Here goes my .htaccess file content.

Options +FollowSymLinks
RewriteEngine On 
RewriteRule ^online-products$ products.php?type=online
RewriteRule ^land-products$ products.php?type=land
RewriteRule ^payment-methods$ payment-methods.php
RewriteRule ^withdrawal-methods$ withdrawal-methods.php
RewriteRule ^deposit-methods$ deposit-methods.php
RewriteRule ^product-bonuses$ product-bonuses.php
RewriteRule ^law-and-regulations$ law-and-regulations.php
RewriteRule ^product-news$ product-news.php
RewriteRule ^product-games$ product-games.php
RewriteRule ^no-products$ no-products.php
RewriteRule ^page-not-found$ notfound.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^casinos/(.*)$ product.php?id=$1
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ cms.php?link=$1
ErrorDocument 404 /notfound.php

      

What I am trying to achieve is that the first set of rules apply to some specific keywords that should be redirected to specific hard-coded pages. But anything else of those keywords should be redirected to cms.php as a parameter that you can see.

But the problem is that every keyword is redirected to cms.php. Whereas I want any other keyword other than the one already hardcoded in the .htaccess file should go cms.php. Not just every keyword.

Example:

www.sitename.com/online-products -> www.sitename.com/products.php?type=online
www.sitename.com/about-the-website -> www.sitename.com/cms.php?id=about-the-website
www.sitename.com/product-news -> www.sitename.com/product-news.php

      

Another problem I am facing is that I cannot use any keyword with space. Like "online products" is ok, but I can't use "online products".

Please help me with your expertise. Thanks a lot in advance for your kind help. Appreciate this.

+2


a source to share


2 answers


You can solve the first part by adding [L] to the end of your rules, for example:

RewriteRule ^page-not-found$ notfound.php [L]

      

This should prevent any subsequent rules from running. See: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule



If you need to have space in the url, you should do this:

RewriteRule ^online\sproducts$ products.php?type=online [L]

      

0


a source


Here's the updated code:



Options +FollowSymLinks
RewriteEngine On 
RewriteRule ^online\scasinos$ casinos.php?type=online
RewriteRule ^land-casinos$ casinos.php?type=land
RewriteRule ^payment-methods$ payment-methods.php
RewriteRule ^withdrawal-methods$ withdrawal-methods.php
RewriteRule ^deposit-methods$ deposit-methods.php
RewriteRule ^casino-bonuses$ casino-bonuses.php
RewriteRule ^law-and-regulations$ law-and-regulations.php
RewriteRule ^casino-news$ casino-news.php
RewriteRule ^casino-games$ casino-games.php
RewriteRule ^no-deposit-casinos$ no-deposit-casinos.php [L]
RewriteRule ^page-not-found$ notfound.php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^casinos/(.*)$ casino.php?id=$1
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ cms.php?link=$1
ErrorDocument 404 /notfound.php

      

0


a source







All Articles