That looks like a very smart thing to do - and a good way to do it! :tup:
HOWEVER, I’d first get your regex right! Don’t you NEED to ahve something in your atoms besides -wallpapers?[indent]Hint: The * means ZERO or more whereas + means one or more.[/indent]
Which still isn’t working, but at least that “-f” flag condition is matching now with the full path.
However, now that I think about that and comment out that last RewriteRule I was used for testing, it works like a charm. Well, at least in this test it’s working, I still need to see about my stylesheets/etc out of the sandbox.
I have a tendancy to make a mess on my test box, a lot of times I leave stuff in that doesn’t belong & just keep a mental note for when I get it going live.
Here’s the [generic-ized] htaccess for the live site where the application is running in the DocumentRoot.
Options +FollowSymLinks -MultiViews -Indexes
AddDefaultCharset utf-8
ErrorDocument 403 "<title>Access Denied</title>Access Denied
<Files "config.php">
Order Allow,Deny
Deny from All
</Files>
<Files "common.php">
Order Allow,Deny
Deny from All
</Files>
<Files "php.ini">
Order Allow,Deny
Deny from All
</Files>
RewriteEngine on
RewriteBase /
## www
RewriteCond %{HTTP_HOST} ^domain
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301]
##index
RewriteRule ^/*$ index.php [R=301]
## cache
RewriteCond /full-path-to-DocumentRoot/html_cache%{REQUEST_URI} -f
RewriteRule \\.html$ /html_cache%{REQUEST_URI} [L]
## category and page links
RewriteRule ^([a-z0-9\\-]*-wallpapers)-([0-9]*)\\.html$ index.php?cat=$1&page=$2 [L]
## old converter demo to new converter
RewriteRule ^converter-script-demo.* converter.php?from_demo=yes [QSA,R=301]
In the htaccess files for my /cache & /style directories I turn the RewriteEngine off.
I had the application print a <!–NEW–> comment at the beginning of the output when it was being displayed immediately after generation, but not saving that comment to the cache file.
Everything appears to be working live at the moment.
It should NOT be working - not as well as you think, anyway!
Options +FollowSymLinks -MultiViews -Indexes
AddDefaultCharset utf-8
ErrorDocument 403 "<title>Access Denied</title>Access Denied[COLOR="Red"]"[/COLOR]
<Files "config.php">
Order Allow,Deny
Deny from All
</Files>
<Files "common.php">
Order Allow,Deny
Deny from All
</Files>
<Files "php.ini">
Order Allow,Deny
Deny from All
</Files>
RewriteEngine on
[COLOR="Red"]RewriteBase /[/COLOR]
[COLOR="Red"]# ONLY use if you have something from mod_alias to correct[/COLOR]
## www
RewriteCond %{HTTP_HOST} ^domain
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301[COLOR="Red"],L[/COLOR]]
[COLOR="Red"]# Which version of Apache?
# You wouldn't forget the ; at the end
# of a PHP statement would you?
# Without the Last flag, it gets ANDed with ...
[/COLOR]
##index
RewriteRule ^/[COLOR="Red"]?[/COLOR]$ index.php [R=301[COLOR="Red"],L[/COLOR]]
# WHY * instead of ? How many leading ////'s do you expect?
# Again, which version of Apache? Apache 2 insists on NO leading /'s
# Without the Last flag, ANDed with the following ...
## cache
RewriteCond [COLOR="Red"]/[/COLOR]full-[COLOR="Red"]web-[/COLOR]path-to-DocumentRoot/html_cache%{REQUEST_URI} -f
RewriteRule \\.html$ /html_cache%{REQUEST_URI} [L]
[COLOR="Red"]# The version of Apache makes a difference with the leading /
# This will ONLY work for a subdirectory (no start anchor) OR
# with Apache 1.x![/COLOR]
## category and page links
RewriteRule ^([[COLOR="Red"]-[/COLOR]a-z0-9][COLOR="Red"]+[/COLOR]-wallpapers)-([0-9][COLOR="Red"]+[/COLOR])\\.html$ index.php?cat=$1&page=$2 [L]
[COLOR="Red"]# This is Apache 2.x ONLY
# Use + (ONE or more) rather than * (ZERO or more)![/COLOR]
## old converter demo to new converter
RewriteRule ^converter-script-demo.* converter.php?from_demo=yes [QSA,R=301]
Sorry to burst your bubble but there are significant problems! Ask if you don’t understand my embedded comments.
What should I have in mod_alias for the RewriteBase ?
I was under the impression that a R=xxx flag sent the request back for immediate external redirection, I placed the L flags to remind me. I guess I need to re-examine my rewrite log for that so I can fully understand how it’s doing it. Thanks!
> “WHY * instead of ? How many leading ////'s do you expect?”
Same reason I used * over + in the following rule.
> # This is Apache 2.x ONLY
# Use + (ONE or more) rather than * (ZERO or more)!
I’m positive that it’s working as expected on Apache 1.3.33 CGI and 2.2.8, is there some sort of silent side-effect I may not see since I’m unable to use a RewriteLog on the 1.x server ?
I’m fairly versed in Perl-compatible & JS regex. I’m not sure why I always think mod_rewrite only supports * rather than +, which is why I tend to use the former.
I was thinking that it woud be fine since the application code will catch it, but now that I think more about it there could end up being multiple URLs pointing to the first page if I let the application catch it.
Yeah, yeah, yeah, so I AM pedantic . I used to work launching $B spacecraft across the solar system. Little things (like a change in sign in a guidance equation) have cost $M and years of man-hours to find after a lost mission so I do look into the details and I do know specifications (and how to use them properly).
Ah ok. It was highlighted with a different color last time, since the quote was all the same color this time I assumed it was just a quote. Thanks, and I apologise if I was rude. Consistency, consistency, consistency.
The important thing is that it’s working now, & I believe the main issue with why it wasn’t working in the beginning had to do with me not using a full path in the RewriteCond that uses the -f flag.
Though, not I am a tad confused & I’m actually not 100% sure that was the issue. :?
I believe the reason for the initial problem was the question of Apache 1.x vs Apache 2.x, specifically within RewriteCond cache/%{REQUEST_URI} -f (NO match if Apache 1.x). As I’d said, the rest was okay (until you showed the whole lot!).
If you’re still confused, let me know where and we can get it straightened out (I tried within the indented sections - perhaps I should have italicized them?). The important thing here is not that it’s working but that you understand why it is!