Forum Moderators: phranque
Welcome to WebmasterWorld!
If you have the line breaks in your file, it won't work...
# Make sure have the correct options setting:
# If you get a server error, comment out (# = Comment) or delete the following.
Options +FollowSymLinks
# Make sure you turn the engine on:
RewriteEngine on
# Make sure the rule is on one line, and you use the [L] flag, unless you know you don't need it:
ReweriteRule ^shop/mens-tops/([0-9]+)$ /shop/index.phpc=13&p=$1 [L]
# Make sure you have a look in the Library [webmasterworld.com] for more information than I can give you in a single post.
- no break
- with/without Options +FollowSymLinks
- RewriteEngine on
but still fails
here my finding, if i use URL(it works!)
URL: http://example.com/shop/mens-tops-1053.html
RewriteRule shop/mens-tops-(.*)\.html$ shop/index.php?c=11&p=$1
------
but i need,
URL: http://example.com/shop/mens-tops/1053
the difference is only after tops- VS tops/
I honestly don't have any idea why and maybe he will, but I haven't looked into it enough and don't, because I just needed the flipping rule to work... I used exactly the same pattern, but removed the anchors and it matched, and the reason I'm suggesting it is it's only happening with my extensionless URLs on the site and yours happen to be entensionless... so try:
# Try this 1st:
RewriteRule ^shop/mens-tops/([0-9]+) /shop/index.php?c=11&p=$1 [L]
# If that doesn't work, try:
RewriteRule shop/mens-tops/([0-9]+) /shop/index.php?c=11&p=$1 [L]
# Make sure you use the [L] Flag (last) on the right side of your rules unless you know you don't need it & I always recommend using the preceding / on the right side of your rules so it's a server relative URL, because it generally prevents extra, unnecessary headaches from an already difficult module.
# The biggest problem with removing the anchors is sometimes you match too much which is not good, so you have to make sure you have rules in the correct order and eliminate URLs which should not qualify for a rule, but do since there is no anchor from being processed ASAP.
URL: http://example.com/shop/mens-tops/1053.html
URL: http://example.com/shop/mens-tops/1053.php
URL: http://example.com/shop/mens-tops/1053anything-else-here
Which could easily duplicate your content.
The follwing might not be exact, and you'll need to test, but this should be close:
RewriteCond %{THE_REQUEST} ^[A-Z]{2,6}\ /[^/]{4}/[^/]{9}/$1\ HTTP/1
RewriteRule ^shop/mens-tops/([0-9]+) /shop/index.php?c=11&p=$1 [L]
# I think the end anchor was the issue, but haven't looked at the site in a few days and don't remember off the top of my head, so I used the one with the start anchor and no end-anchor as an example in this ruleset.
RewriteRule ^shop/mens-tops-(.*)\.html$ shop/index.php?c=11&p=$1 [L]
===== PASS =========
http://example.com/shop/mens-tops-1053
RewriteRule ^shop/mens-tops-(.*)$ shop/index.php?c=11&p=$1 [L]
======= FAIL (partial) =======
http://example.com/shop/mens-tops/1053
RewriteRule ^shop/mens-tops/(.*)$ shop/index.php?c=11&p=$1 [L]
ALL my CSS rules are missing.
// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];
$webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot = str_replace('library/config.php', '', $thisFile);
define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);
============================================
alot of my website PHP files (top) has,
<?php
if (!defined('WEB_ROOT')) {
exit;
}
?>
===========================================
i have a feeling 'exit' caused my CSS to break. just my 2 cents
===========================================
my directory is as follow,
/public_html/shop
/public_html/shop/library
/public_html/shop/library/config.php
ALL my CSS rules are missing.
Check your URLs...
My guess is their directory relative, rather than absolute or server relative.
IOW:
I'm guessing they're this:
path/to-the-css.css
Not:
/path/to-the-css.css
OR
http://www.example.com/path/to-the-css.css
===== PASS =========
http://example.com/shop/mens-tops-1053.html
RewriteRule ^shop/mens-tops-(.*)\.html$ shop/index.php?c=11&p=$1 [L]
===== PASS =========
http://example.com/shop/mens-tops-1053
RewriteRule ^shop/mens-tops-(.*)$ shop/index.php?c=11&p=$1 [L]
======= FAIL (partial) =======
http://example.com/shop/mens-tops/1053
RewriteRule ^shop/mens-tops/(.*)$ shop/index.php?c=11&p=$1 [L]
You're could run into the same issue above as I noted with removing the end anchor by using (.*), but in thinking about it a bit more, as long as you serve a proper 404 within your PHP by checking for a match of the passed variable and serving a 404 if there is no match, you should be able to get away with a 'less precise' match... It's something to 'triple check' twice on 3 different days though, because if you don't serve a 404 from the PHP when the variable is not an exact match, but rather deliver the content you could triplicate your content and not even know you did it.
Also, if you are going to match to 'match everything' I would recommend using ([^.]+) rather than (.*) if there is anything after the (.*) in the pattern to be matched, so you prevent recursion.
([^.]+) = 'not a dot' one or more times, so this:
RewriteRule ^shop/mens-tops-(.*)\.html$ shop/index.php?c=11&p=$1 [L]
Would become:
RewriteRule ^shop/mens-tops-([^.]+)\.html$ shop/index.php?c=11&p=$1 [L]
Not sure what you mean in your second question?
If you are trying to reference it in the rewrite you would just surround the portion you want to 'back-reference' in parenthesis:
RewriteRule ^shop/(mens-tops/)(.*)$ shop/index.php?c=$1&p=$2 [L]
$1 = mens-tops/
$2 = the numbers stored previously as $1.
* Always count the ( to know which number to use...
By the way, can i have someone review below codes that i have written? eg. if i missed some security pt, some symbols or better way of implementing.
# BY Sex (where mens_id = 2)
#(bef) [mysite.com...]
#(aft) [mysite.com...]
RewriteRule ^[S-Ss-s]hop/[M-Mm-m]ens/$ shop/index.php?c=2 [L]
-------
# BY Sex > ClothType (where tshirt_id = 13)
#(bef) [mysite.com...]
#(aft) [mysite.com...]
RewriteRule ^[S-Ss-s]hop/[M-Mm-m]ens/[T-Tt-t]-shirts/$ shop/index.php?c=13 [L]
-------
# BY Sex > ClothType > Brand
#(bef) [mysite.com...]
#(aft) [mysite.com...]
RewriteRule ^[S-Ss-s]hop/[M-Mm-m]ens/[T-Tt-t]-shirts/(.*)/$ shop/index.php?c=$1 [L]
-------
# BY Sex > ClothType > Brand > Product
#(bef) [mysite.com...]
#(aft) [mysite.com...]
RewriteRule ^[S-Ss-s]hop/[M-Mm-m]ens/[T-Tt-t]-shirts/(.*)/(.*)/$ shop/index.php?c=$1&p=$2 [L]
Make a similar correction for "[M-Mm-m]" and "[T-Tt-t]".
Better yet, add external redirect rules to redirect mis-cased URLs to correct-case URLs before invoking your internal rewrites. Then make sure that the links on your site refer only to the correctly-cased URLs. This will avoid duplicate content problems with search engines...
Jim