How to hide a folder from a url.
For example:
If I enter localhost/template I need you to read the directory: localhost/folder/template but do not want to see /folder
I just want to see this in the url: localhost/template
This looks pretty straight forward... You will find many existing answers to this here on SO, once you search for it. Since you are a new user here is a possible approach to point you into the right direction:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?template(/.*)?$ /folder/template$1 [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 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
I need to remove all GET parameters from URL and get them by $_GET. The structure will be like this
From:
example.com/?section=DP&id=366
OR
example.com/index.php?section=DP&id=366
To:
example.com/something-dynamic-from-db,DP-366.html
How can i get this?
No, you cannot have a literal comma (",") in a URL, it is an invalid character in there. You could go for https://example.com/something-dynamic-from-db/DP-366.html though. This should point you into the right direction:
RewriteEngine on
// some other. more specific rewriting rules here
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RequestRule ^/?.+/(\w+)-(\d+)\.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 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).
Guys i have this following code which is does its job quite good but there is one problem when i go example.com/ara.php?name=hey it doesnt redirect to
example.com/pdf-ara/hey i need help.
but when i go to example.com/pdf-ara/hey it works
RewriteEngine On
RewriteRule ^pdf-ara/([0-9a-zA-Z-_]+)$ ara.php?name=$1 [L,QSA]
So now your question is why the internal rewriting works, but no external redirection is performed, right?
Well the answer is: you did not implement any such rule. Take a look at this appraoch:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^name=([\d\w-_]+)$
RewriteRule ^/?ara\.php$ /pdf-ara/%1 [R=301]
RewriteRule ^/?pdf-ara/([\d\w-_]+)$ /ara.php?name=$1 [END]
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...
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).
Hi Friends I Want to create new page as per country name dynamically i create them as per query and links also working but i got a problem i want to remove page name from url where am put all this code
now Links Are Like
https://www.example.com/result/canada....................After use Htaccess This Url Is Working Fine
orignal Url is (https://www.example.com/result.php?canada)
But
I Want This Url Like
https://www.example.com/canada
Please Tell Me The Right Way To Do with Htaccess
My Site Is in Core Php. Not In Wordpress
You want something like that:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(\w+)/?$ /result/$1 [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 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 redirect any queries on non-existent files to one php file.
Im trying to make works nexmo inbound SMS.
I don't have any experience in .htaccess, that why I ask the community..
Thanks for your help.
Please note that you re expected to find a solution yourself by at least trying to solve your task yourself. There are many examples for what you ask in answers here on SO and there also is an excellent documentation of apache's rewriting module two clicks away. So "I don't have any experience" is not a good reason to not try yourself but simply ask us for a solution. Please consider that.
Anyway, here is the solution you ask for:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /path/to/file.php [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).
How to replace url use htaccess ? My url :
domain.com/xem/?i=example
i want replace to
domain.com/xem/example
I want to replace these links without error, please help me!
An internal rewrite to /?i=example makes little sense (I assume that is what you actually ask, domain.com?i=example makes even less sense, or do you really have a folder nameddomain.com on your system?). Instead you should rewrite to your actual router script or logic, so something like
RewriteEngine on
RequestCond %{REQUEST_FILENAME} !-f
RequestCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(\w+)/?$ /index.php?i=$1 [END]
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.
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.
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).