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.
Related
As opposed to many questions here in StackOverflow, I'm looking for something a little different. I have a Wordpress install in a subfolder of my domain called "blog". The main part of the website is a Magento website. I'm looking to take any instance where "blog" is part of the URI, and make sure it's untouched by the myriad of other RewriteRules in Apache.
As a few examples:
http://www.example.com/blog/wp-admin/
http://www.example.com/blog/
http://www.example.com/blog/save-money-groceries-without-coupons/
...should all direct to the Wordpress site found under /blog/
http://www.example.com/
http://www.example.com/plumbing/faucets.html
http://www.example.com/about/family-history.html
...should all direct to the Magento site that is currently found under the root directory
What is the best practice in writing the .htaccess file to achieve this result?
To redirect http://www.example.com/blog/wp-admin/ to http://www.blog.example.com/wp-admin/ you can add the following to the .htaccess file
RewriteEngine On
RewriteRule ^blog/(.*)$ http://www.blog.example.com/$1 [L,R=301]
I'm not an expert on setting up Apache servers but I think you want your WordPress install in a completely different folder to Magento and then use Alias in your .conf file. You can read about the Alias directive here.
For example in my Apache .conf files I have
Alias /blog/ "/full/path/to/wordpress/htdocs/"
This way the folder /full/path/to/wordpress/htdocs/ has its own .htaccess and its own index.php - which is what you are going to want for running WordPress without jumping through hoops.
Remember to restart Apache if you update the .conf file.
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/
I am stuck into a weird problem.
I have a file at the location /public_html/academics/courses.php
I want .htaccess to mod_rewrite the URLs as below:
Original URL: http://niecdelhi.ac.in/academics/courses/
After mod_rewrite: http://niecdelhi.ac.in/index.php?inc=/academics/courses/
What I want, basically, is to mod_rewrite all URLs to index.php and pass the URL as a parameter named "inc". Then, in the index.php I include the file by doing include($_GET['inc']);
mod_rewrite is working for some pages on the website. and I am getting the URL in $inc. But, it is not working at all for other pages.
For example, consider the two files that exist on the server:
http://niecdelhi.ac.in/academics/courses.php
http://niecdelhi.ac.in/academics/library.php
mod_rewrite is working for the first, the file gets included in index.php
But for the second I get the plain existing file. not the one included in index.php
I hope you understand the problem that I am facing. Please provide me with the solution.
.htaccess file
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !\..*$ [NC]
RewriteCond %{QUERY_STRING} (.*) [NC]
RewriteRule ^(.*)$ index.php?inc=$1&%1 [L]
Page working: http://niecdelhi.ac.in/academics/courses/
Page not working: http://niecdelhi.ac.in/academics/library/
*EDIT*
There is no other .htaccess anywhere. Although, I have found a clue about what is happening. The problem is happening only in Linux server. The code is working correctly in Windows server.I have a Linux server with PHP 5.2.16.
Also, regarding some pages working and some not. I have found that only those pages are working which have a folder with identical name in the same directory. For example, The academics directory is as below:
academics/
|_ courses/
| |_ mba.php
| |_ mca.php
|_ courses.php
|_ library.php
Now, Since courses.php has a folder with identical name in same directory. It gets mod_rewrite fine. But library.php is not getting mod_rewrite.
Linux server is skipping the mod_rewrite for the files that actually exist. Why so ??
My only guess is that there is another .htaccess somewhere in your structure (most obviously inside /academics/ ) that is overriding the rule for "library".
Could there be another mod_rewriting rule inside that folder that is kicking in for the word LIBRARY and probably messing up your rewriting.
Note that it might also be a native apache issue. For example, in ubuntu, by default in version 10.10 (i think thats it) if you had a /javascript/ folder, it would be short circuited to /usr/lib/javascript or something like that...
Check all possible instances of mod rewrite in httpd.conf, all dynamicaly loaded .conf files, your vhost file and finaly the path of your document root...
I have a php websites hosted on a server. I use CPanel to manage it. public_html has lets say following directory structure
public_html
- dir1
- dir2
- dir3
- ....other files.....
- website2home
Now I am trying to make website2home as the base directory of my website, but files inside website2home use some files from public_html folder and some files from within itself.
THE PROBLEM
When I assign a domain name to website2home, It does not reads the files from public_html folder (in fact, public_html folder is not visible) and shows some php warnings and some 404 not found errors. But lets say the domain name for original website is www.aaa.com, then if I access website2home by using www.aaa.com/website2home all works fine.
So My Question...
Is there any way to set the base directory, so that my website2home fetches all files and correct files without replacing hundreds of filepaths in php code?
Please answer considering that I don't want to modify source files of website.
I believe you are looking for some kind of .htaccess configuration. For instance, you may set your website2home folder as base folder for your www.aaa.com domain and then redirect some file access to other folders using .htaccess, something like this..
RewriteEngine on
RewriteRule captcha.jpg ../captcha.jpg
RewriteRule \.pdf$ ../pdf_files/$1
Have a look to mod_rewrite documentation
Edit: If, for some reason, the ../ redirection doesn't work, you always can redirect all your files to a pseudo-index PHP page. For instance:
RewriteEngine on
RewriteRule captcha.jpg my_index.php?access=../captcha.jpg
RewriteRule \.pdf$ my_index.php?access=../pdf_files/$1
And then, in your index PHP page you can simply load your PHP files in other folder:
require "../pdf_files/$requested";
A site has an existing system (lets call it mysite)
and the client asks to put in magento.
My directory structure goes something like this:
ROOT
-index.php (this is the app's main controller)
-.htaccess
/blog (runs wordpress)
/assets (current system's media folder)
/magento (this is where all magento files go)
Problem is if I set up magento and specify in the installation that base URL is http://example.com, magento loads up mysite.
Leaves me no choice but to setup magento with base URL set to http://example.com/magento/ and it runs perfectly.
However the client wants me to feel hell and asks me to hide magento in the URL.
I’m not really versed in .htaccess and I know only simple rewrite codes so I tried forwarding any HTTP requests that start with /magento to the magento folder and came up with:
RewriteCond %{REQUEST_URI} !^/magento(.*)
RewriteRule (.*) /magento/$1 [L]
Just when I thought it was working, mysite links all became unaccessible and forwards to the magento system displaying it's 404 page.
So, uhm, can I ask for help how to construct the .htaccess to hide the /magento/ on the URLs without affecting the current system aka mysite?
Because you have existing applications off the webroot, you cannot get away with using nothing instead:
### webroot/.htaccess
RewriteRule ^whatiwanttouseinsteadofmagento/(.*)$ magento/$1 [L]
From how I see the problem you will not be able to hide magento completely and use your site as well in the same time.
If you want Magento in the root of the public folder you should just point the virtualHost to your magento installation but this will let your blog and your main controller out of the public view. This is more or less the same with what you did by redirecting all calls in the .htaccess to magento folder.
What I suggest is to change the magento name to something more anonymous like "shopping" or "cart", and remember that a folder rename is preferable to a .htaccess file in terms of security and performance.
Let's look at it:
RewriteCond %{REQUEST_URI} !^/magento(.*)
So we're saying the condition is anything that is not /magento(.*), so everything but that directory? This would redirect everything, including your blog, assets, and any other directories.
Without specifying each and every file that needs to be redirected to the magento directory, there really is no easy way of doing it. I suppose you could redirect any file that does not contain a "/" in it and ends with the extension .php to the magento directory. That way only files in the root web directory will redirect to magento, but if you used other directories inside the magento directory you'd still need to add separate rules for them.
this answer comes very late but I guess you wanted something like
RewriteCond %{REQUEST_URI} !^/(blog|assets|magento)(.*)$
RewriteRule ^(.*)$ /magento$1 [L]