.htaccess some folders to subfolder/folders - .htaccess

About .htaccess I will like to do following
www.domain.com go to this folder www_folder
url in browser www.domain.com
www.domain.com/yyy go to this folder www_folder/yyy/
url in browser www.domain.com/yyy
And i will like
www.domain.com/abc go to this folder www_folder/xxx/abc
url in browser www.domain.com/abc
www.domain.com/def go to this folder www_folder/xxx/def
url in browser www.domain.com/def
I will not show folder xxx in the browser url.

Assuming that the www_folder is what your http server's host's DOCUMENT_ROOT points to all you'd have to do is rewrite the URLs /abc and /def, since / and /yyy should already do what you ask. So what is left are these two rewriting rules to get implemented:
RewriteEngine on
RewriteRule ^/?abc$ /xxx/abc [END]
RewriteRule ^/?def$ /xxx/def [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).

Related

Rewrite Rule in .htaccess file

The URL in my site is https://www.artmail.xyz/single.php?id=37
I want to make it https://www.artmail.xyz/single/37.html
I added the following line in my .htaccess:
RewriteRule ^([^/]*).html$ /single.php?id=$1 [L]
But nothing is happening. No error also.
Is it possible Mod rewrite is 'off' with my server? How can I check. Please help.
Thanks
Certainly it is possible that the rewriting module is not active:
it is an optional module that needs to be loaded into the server
you need to enable it for the specific location (check the documentation for the AllowOverride directive)
you need to use the well known RewriteEngine on initially
But more important is that your matching pattern actually matches what you want it to match:
RewriteEngine on
RewriteRule ^/?single/(\d+)\.html$ /single.php?id=$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).

Htaccess rewrite when folder is in url

I need a rules that find a folder in my url and rewrite folder before.
Example:
www.site.it/folder1/sub1/detail/page.html =>
www.site.it/newfolder/sub1/detail/page.html
www.site.it/folder2/sub1/detail/page2.html => www.site.it/newfolder/sub1/detail/page2.html
www.site.it/folder1/fodler2/sub1/detail/page3.html => www.site.it/newfolder/sub1/detail/page3.html
Sounds pretty straight forward:
RewriteEngine on
RewriteRule ^/?([^/]+)/sub1/(.*)$ /newfolder/$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).

How to redirect a path without changing the URL while passing a GET parameter?

Website: example.com
Link with GET parameter is sent to user through email: example.com/click?var=1a2b3c (<= random hash)
When the user clicks the link "example.com/click?var=1a2b3c", he should be redirected to "example.com/admin/click.php?var=1a2b3c" where a function processes the GET parameter. The redirected URL should not be displayed and stay "example.com/click?var=1a2b3c".
Who can help me out with the code for the .htaccess file?
Sound like you do not want a redirection at all, but an internal rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^var=[a-z0-9_]+$
RewriteRule ^/?click$ /admin/click.php?%{QUERY_STRING} [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).

redirect 301 country subfolder to frontpage

i look for a redirect pattern which redirects all URLs with the slug /at/ to the frontpage of my site.
example:
https://www.example.com/at/shop/systeme/alf/product.html
should redirect to:
https://www.example.com/de/shop/ (this is my frontpage)
i have hundrets of urls with /at/ in the slug. All these Urls should redirect (301) to
https://www.example.com/de/shop/
i hope somebody can help me
best regards
Tom
This probably is what you are looking for:
RewriteEngine on
RewriteRule ^/?at/ /de/shop/ [R=301,QSD]
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 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 remove folder name from subdomain

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).

Resources