I've been searching for hours now hoping to find a solution for my problem. But all I find is something like an URL-rewrite from folder to folder. Nothing related to my question.
Well I'm trying to achieve an URL-rewrite from a script (e.g. confirm.php) to a script in a subfolder (e.g. scripts/confirm.php).
Something like this
www.example.com/confirm.php?id=somevalue&key=somevalue
to
www.example.com/scripts/confirm.php?id=somevalue&key=somevalue
where the values of the parameters are variable and the page can be visited via http/https and with or without www.
Try below rule, in your root directory, I am assuming confirm.php is not exist in root directory.
RewriteEngine On
RewriteRule ^confirm\.php$ scripts/confirm.php [QSA,L]
Related
I have a order page in the following path
https://example.com/backend/web/order
And I want to display it as
https://example.com/order
What should be the htaccess code (please let me know of every step if possible so I can learn also). Where should I place the htaccess file? Inside the backend folder or the root folder.
To change https://example.com/backend/web/order to https://example.com/order you can use the following rule in htaccess in your root folder :
RewriteEngine On
RewriteRule ^order /back-end/web/order [L]
The rule above makes it possible to access your old URL as http://example.com/order .
I have tried to find a solution to my problem but I have not been able to find any questions/answers that address this specific issue.
I've been tasked with moving a website that was built under its own domain - www.example.com - to now reside in a subdirectory of another site - www.otherSite.com/example.
The site to be moved was built with many references to $_SERVER['DOCUMENT_ROOT'] as well as many relative URLs that start at the root. For example:
<?php include $_SERVER['DOCUMENT_ROOT'] . '/nav.php'; ?>
and
/images/logo.jpg
The problem, of course, is that all of those references to the root for the site moving to the subdirectory will reference www.otherSite.com thereby breaking all of those URLs.
I'm hoping that there's a some way, possibly using .htaccess in the subdirectory, to set that subdirectory as the root for the site in that subdirectory.
Note - I am on shared hosting and do not have access to httpd.conf.
Thanks very much.
On www.otherSite.com host place this code in DocumentRoot/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(www\.)?domain\.com/example/ [NC]
RewriteRule ^((?!example/).*)$ /example/$1 [L,NC,R=301]
Have you tried redirecting to the sub-folder from your cpanel?, have you check if some of the settings were stored in a database for the site if any?
Please add more codes from the site so we can understand how the codes look like.
I have had to change the name of a page on my wordpress site. In the url structure the page has many sub pages which are illustrated as follows:
www.mysite.com/folder1/plus whatever else may come here
Basically I want to do a wildcard redirect where any URL matching the folder1 part of the URL gets caught and redirected to the following:
www.mysite.com/newfolder1/folder2/
The following redirect works for the above situation
RewriteRule ^folder1/?(.*) http://www.mysite.com/newfolder1/$1 [R=301,L]
But fails and give a 404 for the following
www.mysite.com/folder1/folder2/folder3
It will not redirect beyond the folder2 depth. Why is this?
Following up on the comments:
The problem sounds like the .htaccess file (or the rules you're talking about) is in the wrong location.
As far as my understanding goes, Apache reads all the .htaccess files (and other server configs that do redirects) from the "top" down - i.e., .htaccess files in subfolders are processed after .htaccess files in the root folder.
Ok, I'm clueless here...
I need to rewrite a directory structure and all sub-directories within it to a directory within the same server, but a root that is before the directory.
For example:
http://www.mydomain.com/Themes/default/css/folder
and all directories called upon after folder. Such as folder/sub_folder or folder/afolder/anotherfolder, it needs to include ALL sub-directories within the folder directory.
should be redirected to this:
http://www.mydomain.com
How do I do this via a .htaccess file within the folder path http://www.mydomain.com/Themes/default/css/folder?
Please someone help.
Thanks guys :)
The files within the directory structure still need to be accessible for that structure when called via PHP, but I don't want people being able to browse to http://www.mydomain.com/Themes/default/css/folder and be shown all subdirectories within that folderpath and/or all files. Same thing for all sub-directories that follow that folder path.
I'd like to be able to place the .htaccess file within the http://www.mydomain.com/Themes/default/css/folder directory on the server, but don't know exactly what code to use for this.
ALSO, even more challenging... The domain name can change, so I'd rather not use the domain name within the .htaccess file, instead perhaps use .. or . to go up a directory or a different method of grabbing the domain name within the .htaccess file.
Create a .htaccess file in /Themes/default/css/folder and place these lines there (it requires mod_rewrite):
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ http://%{HTTP_HOST}/ [R=301,L]
It will redirect (301 Permanent Redirect) all requests to a folder to a homepage. If file is requested, it will allow it.
If you want to have it working for folders as well as files then remove the RewriteCond line -- it will redirect ALL requests (even for non-existing URLs) to a homepage.
If you will see "500 Internal Server Error" after creating such file, then it is your server configuration: mod_rewrite may not be enabled or it's directives (RewriteRule, RewriteCond, RewriteEngine) are not allowed to be placed in .htaccess. In any case -- check Apache's error log for exact error message (it will give you the exact reason).
http://www.besthostratings.com/articles/prevent-directory-listing.html
IndexIgnore *
Is it possible to set a default folder to access instead of a file like "index.html".
What I'd like to to is make it so that when a person visits my site they get redirected to a folder within the root of the domain. I am using a blogging engine and I need it to show up as the homepage but I don't want to install it in the root because I have other folders and files that need to be in the root directory. And I don't want to put them inside the blogging software's folder. I also don't want to use a 301 or 3XX redirect for SEO purposes.
If there's a way to do what I'm asking let me know. If not, let me know the best option otherwise.
Try this mod_rewrite rule:
RewriteEngine on
RewriteRule ^$ foo/bar [L]
This will rewrite requests to the directory where this rule is applied to to foo/bar. So if you put this rule in the .htaccess file in your document root and request http://example.com/, it will get rewritten to http://example.com/foo/bar.