You can try to such redirect with the Apache directive ErrorDocument: http://httpd.apache.org/docs/2.2/mod/core.html
Sure the directive ErrorDocument will work for you if your website works under Apache. Anyway if HTTP/HTTPS requests are handled by Apache then you need to put something like:
ErrorDocument 404 some_error_document.ext
into .htaccess file located in the document root of your php based website. The error code 404 means “not found”. So the above directive will call “some_error_document.ext” when the error 404 (not found) appears.
ErrorDocument directive doesn’t have to be used only for errors 404, and it can do couple of things except from redirecting your visitor.
Example of ErrorDocument syntax:
ErrorDocument error-code some-error-document-file Here is a snippet with ErrorDocument examples:
1ErrorDocument 500 http://example.com/
2 ErrorDocument 404 /pages/errorDocument/error404.php
3 ErrorDocument 403 “You are forbidden to access this page. How many times should I tell you?”
That’s why you should show your code: It’s loopy! Don’t you think that docs/{anything} will match docs/all-ind.php? (.*), the :kaioken: EVERYTHING :kaioken: atom is a nice catch-all but you must know how to limit its effect!
The answer to your question is to give mod_rewrite an exit strategy, e.g.,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^docs/(.*)$ docs/all-ind.php?type=$1 [L]
… will reject the redirection if a filename in the docs folder is requested.
Or
RewriteEngine on
RewriteCond %{QUERY_STRING} !type=
RewriteRule ^docs/(.*)$ docs/all-ind.php?type=$1 [L]
… will reject the redirection if a query string contains a key named type (actually, ending in type).
First, your RewriteCond is superfluous (redundant, repetitious, duplicates the RewriteRule regex).
Second, your RewriteRule says {anything}/{anything_else}/, i.e., two slashes preceeded by any kind of junk. That is certainly not “has / or not in the end.” An optional trailing / defeats the purpose of having a trailing / (because it’s matched by the (.*)). If you want to make that trailing / optional:
Use /? to specify zero or one of the preceding character, i.e., the /
and
You will be forced to use either <base> tags in your scripts or absolute links (because relative links will have to be to two directory levels which cannot happen - at least not without duplicating files which is ridiculous).
Now, back to your original post:
The first thing you said there was that you wanted to add a trailing /. Is that still the case? Can you handle making your css, js, jpg, gif, etc files into directories (MultiViews)?
The second thing you said you want is more garbage after the topic/49817-a-basic-script/ in your URI. Is that still the case?
What I’m getting at here is called Specificity, making sure that you can verbalize what you want mod_rewrite to do (so you can translate that to code). Since I can’t determine what you want (because of conflicting statements), I can’t even begin to suggest pseudo code for you to convert into code.