stop htaccess redirect - php

I accessed a 'superfolder's .htaccess file and accidentally added
Rewrite / http://google.com/
This was done using php. Now I can't access php files in any directory to revert the change.
Is there anything I can do in a subdirectory of root to stop the redirect inside that folder?
Thank you.
And please don't ask more details about the 'accident'.. stupid mistake

I contacted server admin, both laughed at it.. Still interesting though how to stop it redirecting although it shouldn't happen if I use mod_rewrite.
With mod_alias' Redirect, you're screwed. That directive is applied across the board, starting from the path-node where the htaccess file sits (if it's in an htaccess file), or the path-node of the <Directory> block that it sits in. So the only solution is to get an admin to remove it.
With mod_rewrite however, with an htaccess file, it doesn't act the same as within a <Directory> block. Rules inside an htaccess file in a path-node inside a directory has precedence over rules inside an htaccess file in the parent directory. So if you had 2 htaccess files:
/.htaccess:
RewriteEngine On
RewriteRule ^/? http://google.com/
and in /tmp/.htaccess:
RewriteEngine On
RewriteRule ^/?tmp/ http://stackoverflow.com/
And you go to http://yourdomain.com/tmp/, you'll get redirected to http://stackoverflow.com/ because the rules in the tmp directory has precedence over the rules in the parent directory. In face, the rules in the parent directory aren't applied at all unless you've used the RewriteOptions Inherit directive to inherit any rules from the parent directory.
Because of this, you can simply create an htaccess file with the following:
RewriteEngine On
Use FTP to upload it to your subdirectory, and upload the php file that you used to change the parent directory's htaccess file. Then just use your browser and go to that php file in the subdirectory.
Having simply turned on the rewrite engine in your subdirectory, without any rules, means:
I have mod_rewrite active in this directory
Since the rewrite engine is turned on in this directory, ignore all rules in the all parent directories.
Since the mod_rewrite ruleset is blank (no actual RerwiteRule's) nothing happens at all
Accessing this directory, eventhough the rewrite engine is on, mod_rewrite does nothing so it's as if the rewrite engine is turned off.
Sounds counter-intuitive, but that's just how it works.

Connect using your FTP client. Enable hidden files in your FTP client (try FileZilla, this one lets you do that). Delete .htaccess in your superdirectory. If this file has other data in it, copy it to your local computer, make changes and upload it again.
Here is some more help: http://www.intrepid.com.au/how-to-view-htaccess-with-filezilla/

Related

mod rewrite and htaccess with subfolders

I had a site set up on one server, and it has subsequently been moved.
I had a subdomain that processed a link and forwarded it on. However, with the server move the files now sit in a different place!? Let me explain
SERVER A
example.com (run main site)
my.example.com
I was able to create a subdomain and run files in it with no problem. The main domain and subdomain run like separate sites. My .htaccess file on that worked and had the following lines of code:
RewriteEngine On
RewriteRule ^([0-9a-zA-Z]*)$ index.php?profileId=$1
SERVER B
example.com (run main site)
my.example.com (the files now sit in a subfolder in the root of my main domain so example.com/my.example.com.)
This affects my .htaccess file now and although the subdomain is set up. When I run the page I get a "no input file specified error".
How do I resolve this? Its just a simple file to process but my issue is I have 10000 pre printed QR files that I am unable to change so need to resolve my issue.
RewriteEngine On
RewriteRule ^([0-9a-zA-Z]*)$ index.php?profileId=$1
This should still work OK, assuming...
this .htaccess file is now in the document root of your subdomain (assumed to be example.com/my.example.com) and not the main domain's document root.
The index.php file (referenced in this directive) is located at my.example.com/index.php (not example.com/index.php).
Also, make sure that MultiViews is disabled. You might need to add the following to the top of your .htaccess file:
Options -MultiViews

.htaccess Completely rewrite URL to show file in a folder, rather than page in root

So, I have the current file structure:
ROOT
-> /public
-> /user_views
user_handle.php
user_profile.php
user_feed.php
user_settings.php
.htaccess
As you see, the folder user_views contains a few of the possible views that the client could want to look at. What I am wanting, is for clients that insert the URL http://example.com/user/ to be directed to the page user_handle.php. This handle would act as a root file for all /user/ pages, and it would accordingly split into those pages through numerous $_GET requests.
So far, I have the following .htaccess, but it's not working...
RewriteRule ^user/ user_views/user_handle.php [L]
What could I do to get this to work, so that the url http://example.com/user redirects to the user_handle file in the user_views folder?
Thanks!
I'm not sure I fully understand your question, but it seems you would like to make user_handle.php located under public/user_views act as a "router" for the rest of you PHP files and have all requests to /user/ (e.g. /user/?page=1) be processed by user_handle.php.
If that's the case, your rule seems legit. The only thing I noticed (I might be wrong) is that your .htaccess is located outside the public folder. In that's the case, you need to include 'public/' as part of your rule.
I recreated the folder/file structure you described and it has worked for me using the following .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^user/ public/user_views/user_handle.php [L]
</IfModule>
Slight chance this is the problem, but you also might want to double check that mod_rewrite, which is the rule-based rewriting engine is enabled on your server/local environment. It should show up under 'Loaded modules' when you call phpinfo() in any PHP file.
Hope this helps.

change security permission in a website

I have a website that is working properly.I dont know when I do "Domain-name.com/images" It shows me all the images in the images folder present at my site.I dont know why is this.may be this is due to the Directory permissions?But I want to ask know the actual reason behind it
Help will be appreciated.
Note:I am tagging Php and Html because these people might faced this thing while creating website.
This is because there is no index file in the folder, and Apache (assuming Apache) is set to do directory indexes.
Either create an empty index.html or add the following in either apache2.conf (or httpd.conf) or in a htaccess file:
Options -Indexes
You can restrict the folders using .htaccess.
Create .htaccess file in you website root folder and add the following code in it.
RewriteEngine on
RewriteCond $1 !^(css|js|images)
RewriteRule ^(.*)$ index.php/$1 [L]
This is a problem with the configuration of your web server which allows directory listing for your image folder. E.g. on Apache, the most common server software, you would switch it off in the httpd.conf with the directive Options -Indexes in a directory section.
To answer your question: yes. If it's a web accessible directory meaning it resides in the typical webroot folder such as public_html, www, etc and the permissions on the folder are open then anyone can see the contents.

.htaccess in subfolder

I install a new cms (phpmydirectory) in a subfolder. In the root there is a wordpress with friendly url's.
When I activate the friendly url's in phpmydirectory, I get an 404 error in the categories and locations, but no in the listings. The 404 error appear in the blog template and URL.
How fix the -htaccess so the subfolder read the .htaccess in the subfolder ando no the one in root?
Apache always reads all .htaccess files along the path to the root directory. This cannot be changed (except for disallowing use of .htaccess alltogether). The best you can get is making sure that rules for mod_rewrite in the parent directory do not apply. This might be possible using
RewriteRule ^(.*)$ $1 [L]
as the last rule in your phpmydirectory directory.
Do you have the subdirectory specified as the $BASE_URL in your defaults.php file for PMD? I'm operating with a similar setup right now, and did not have to make adjustments to the .htaccess file. However, its not competing with a Wordpress install in the root directory (its an older version of phpmydirectory instead), so that might be causing a different issue than my setup.

How can I use a clean URL only in a subfolder of my website?

I have a web site http://www.mydomain.com
Here I have created a sub folder http://www.mydomain.com/products. I want to change all the page inside the product folder as clean URL. I know .htaccess should be inside product folder. If it's enabled, will it affect all the parent directories and files of my site
I mean http://www.mydomain.com/ here, will it affect the pages here also.
I have one more doubt about .htaccess file, is there a way I can enable mod_rewrite through any code code without directly editing httpd.conf file
Please help me
Thanks
i have one more doubt about .htaccess file, is there a way i can enable mod_rewrite through any code code without directly editing httpd.conf file
You place this line before any rewrite rules in your .htaccess file, which will switch on the rewrite engine - no httpd.conf change required.
RewriteEngine on
If it's enabled, will it affect all the parent directories and files of my site
The .htaccess file will only affect the folder it is in and any subfolder of that folder.

Categories