I am on looking for .htaccess code that block all post requests expect one form with action a query string ?pub=123 i hope you understand what i am saying thanks in advance
Your question is very vague, so only a general, vague answer is possible:
RewriteEngine on
RewriteCond %{QUERY_STRING} !^pub=123$
RewriteRule ^/?path/to/action [F]
This implementation will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
Related
The url of my app is http://example.com/public/login. I want my url to be http://example.com/account/login.
How do I replace text with .htaccess
This thread hides the text only. But I need to replace the text
If you really only want to redirect that specific URL, then this should do the work:
RewriteEngine on
RewriteRule ^/?public/login$ /account/login [R=301,END]
RewriteRule ^/?account/login$ /public/login [END]
If your "app" actually consists of more than just that single URL you will have to modify your question and add more precise details...
For above rule set to work you have to implement it either in the http server's host configuration or, if that is not possible for you, in a distributed configuration file (".htaccess"). In the second case you also need to make sure that the interpretation of such files is actually enabled and the rules are implemented in the DOCUMENT_ROOT folder of your host. See the excellent documentation for more details and good examples: https://httpd.apache.org/docs/current/mod/mod_rewrite.html
In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.
This implementation will work likewise in the http servers host configuration or inside a distributed configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a distributed configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using distributed configuration files (".htaccess"). Those distributed configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
I have this URL:
https://app.mydomain1.com/folder/plugins/mm/api.php?somevariables=1
What I want to achieve is that if "folder/plugins/mm/api.php" is found in the URL, rewrite that URL to use a different domain, and rest of the URL remains the same. So, the above URL should become:
https://files.mydomain2.com/folder/plugins/mm/api.php?somevariables=1
Intent is to use a different server/url for any file upload requests.
Sounds pretty straight forward, you would have found man existing solutions here on SO...
RewriteEngine on
RewriteCond %{HTTP_HOST} ^app\.mydomain1\.com$
RewriteRule ^/?folder/plugins/mm/api\.php$ https://files.mydomain2.com%{REQUEST_URI} [R=301,QSA]
It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...
This implementation will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
I have a list of state urls like this, which are identical except the state name
/Wyoming_Red_Widgets
/Ohio_Red_Widgets
and want to redirect all to:
/red-widgets
Various patterns, although I am newer to Modrewrite / htaccess
Rewrite /([a-z]+)_Red_Widgets /red-widgets/
Nothing happens (no redirect)
Your question is vague, but strictly speaking this probably is the closest answer to what you actually asked:
RewriteEngine on
RewriteRule ^/?.+Red_Widgets/?$ /red-widgets [END]
For this to work you need to make sure that dynamic configuration files (".htaccess" style files) are considered at all by the http server for this location (hint: AllowOverride) and they file is readable for the http server process.
In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.
This implementation will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
I need to write a rewrite rule in my .htaccess file,
I readed tutorials but always fails.
What I want is:
domain.com/en/111/page-title ->redirects to-> domain.com/viewPage.php?language=en&id=111
I dont need the page-title parameter, only the language and id
You most likely do not actually want a redirection rule, but an internal rewriting:
RewriteEngine on
RewriteRule ^/?([a-z]{2}])/(\d+)/ /viewPage.php?language=$1&id=$2 [END]
In case you receive an internal server error (http status 500) using the rule above then chances are that you operate a very old version of the apache http server. You will see a definite hint to an unsupported [END] flag in your http servers error log file in that case. You can either try to upgrade or use the older [L] flag, it probably will work the same in this situation, though that depends a bit on your setup.
This rule will work likewise in the http servers host configuration or inside a dynamic configuration file (".htaccess" file). Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a dynamic configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).
I have Domain name like :
http://test.domain.com/godadmin/login
i want to hide godadmin from URL
Like : http://test.domain.com/login
How ?
Thanks.
Your question is a bit vague, but a general answer is probably the following rule. It will internally rewrite all requests to /... on the host it is defined inside to /godadmin/...:
RewriteEngine on
RewriteRule ^/?(.*)$ /godadmin/$1 [END]
If you encounter an "internal server error" (http status 500), then chances are that you operate a very old version of the apache http server. You will find hints to an unsupported [END] flag in your http servers error log file in that case. Either upgrade your http server or use the older [L] flag in that case, it will probably work the same in this scenario...
That rule should work likewise in the http servers host configuration or in a dynamic configuration file (".htaccess" style file). If you decide to use such a dynamic file then the interpretation of such files needs to be enabled inside the http servers host configuration and you need to place the file in the host's DOCUMENT_ROOT folder.
And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).