I have a bunch rules in my .htaccess
I want to apply a new rule:
if the url is:
http://www.example.com/documentation/invoices/....
I just want to keep the url as it is, it means: I want to bypass all rules
Any idea ?
Since you provided no code there is no way to know if there will be a conflict. However this would go above all the other rewrite rules under RewriteEngine On.
RewriteCond %{REQUEST_URI} ^/documentation/invoices
RewriteRule ^ - [L]
Related
In the .htaccess file of my PHP application I use one simple rewrite to translate my URLs from:
/shop/hats/detroit/
to:
index.php?url=/shop/hats/detroit/
using the following rewrite rule:
# Rule 1
RewriteRule ^(.*)$ /repos/nvp/httpdocs/index.php?url=/$1 [L,QSA]
I would like the following rewrite to work as well:
# Rule 2
RewriteRule ^pic/(.*)$ /repos/nvp/httpdocs/get_image.php?pic=$1 [L,QSA]
But the two rules are kind of overwriting or conflicting with each other. They work each on their own but not together. How can I use all urls to use Rule 1 and only if url starts with pic/ to use Rule 2 instead of Rule 1?
This is because the pattern (.*) matches all uris .
In order to avoid the rules overriding ,you need to reorder your rules and put the specific rules first in order.
# specific rules
RewriteRule ^pic/(.*)$ /repos/nvp/httpdocs/get_image.php?pic=$1 [L,QSA]
#catch-all rules
RewriteRule ^(.*)$ /repos/nvp/httpdocs/index.php?url=/$1 [L,QSA]
In our .htaccess file, we have a bunch of different rewrite rules that we add on to periodically. Also, on our site, we have a directory that we NEVER want to be rewritten. So, above each rewrite rule, we include a condition like this:
RewriteCond %{URL} ^(?!/excludeddirectory/.*$)
RewriteRule ...
Instead of having to remember to add this RewriteCond any time we write a new RewriteRule that might affect that directory, is there a way to write a single line that overrides all rewrite rules in the file and tells the rewrite engine to ignore this directory no matter what?
You can add the following rule above all other rules in your config:
RewriteCond %{REQUEST_URI} ^/excludeddirectory/
RewriteRule .? - [L]
I need to edit my .htaccess to do something like this:
from URL example.com/tag/iphone/iphone-manual to URL:
example.com/iphone/iphone-manual
I just want to remove the tag from its permalink. I don't know whether this could be achieve only by changing htaccess or it had to edit using PHP too.
Here is my current htaccess:
RewriteEngine On
RewriteRule ^tag/.* /tag.php [QSA]
RewriteRule ^([^/]+)/$ a-search.php?q=$1
I assume you want to replace the previous "tag rule" inside your .htaccess file? Because it conflicts with what you ask in this question. I'd say all you need to do is this:
RewriteEngine On
RewriteRule ^tag/(.*)$ $1 [QSA,L]
RewriteRule ^([^/]+)/$ a-search.php?q=$1 [L]
If instead you want to add a specific rule, so an exception, then this probably is what you are looking for:
RewriteEngine On
RewriteRule ^tag/iphone/(.*)$ iphone/$1 [QSA,L]
RewriteRule ^tag/.* /tag.php [QSA,L]
RewriteRule ^([^/]+)/$ a-search.php?q=$1 [L]
A general remark: .htaccess style files are notoriously error prone, they make things complex, are hard to debug and really do slow down the server. They they should only be used in two situations:
if you do not have access to the real host configuration (otherwise palce the rules in there!)
if you require dynamic changes to the rule set by some web application (though think twice about the security implications)
In all other cases it makes much more sense to use the real host configuration instead of .htaccess style files.
i have a little issue that some of you may be able to sort please
in my htaccess i have
RewriteRule apply /index.php?option=com_loans&view=apply&Itemid=102 [R=301,L,QSA]
basically meaning any get requests to apply will be sent on
however i have a page apply.html which with the above is no longer accessible as it creates a redirect loop
anyone know how to change the htaccess declaration so as only apply (and not apply.html) forwards on ?
tnx
Try to add a rewrite condition as well as limiting the matching pattern in the regex:
The condition will make sure that the rule will only be applied if the request isn't for an existing file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^apply$ /index.php?option=com_loans&view=apply&Itemid=102 [R=301,L,QSA]
I've got a .htaccess file that has got a rewrite rule in it as follows which works fine:
RewriteRule ^solicitorsin([^/]+)/all/([0-9]+)$ /search/searchresults.php?county=$1&page=$2 [L]
What I'm looking to do is to keep using this for if the page variable is 2 or higher, but if it's 1 I want to 301 redirect to a separate url (the same site) say http://www.domain.com/solicitorsinCOUNTY/
The problem is that if I try doing this using a 301 redirect or a rewrite rule it still performs the above rewrite rule as well so I end up with http://www.domain.com/solicitorsinCOUNTY/?county=COUNTY&page=1
I haven't done much with .htaccess before so I'm not even sure if this is possible, can anyone help please? It would be much appreciated.
If you are using a rewrite rule, then put the rule for page=1 above the other rule and make sure you have the [L] flag.
Alternatively, you can use RewriteCond to prevent the rule from being run on specific URLS like this:
RewriteCond %{REQUEST_URI} !^solicitorsin([^/]+)/all/1$
RewriteRule ^solicitorsin([^/]+)/all/([0-9]+)$ /search/searchresults.php?county=$1&page=$2 [L]