I need to "internally rewrite" (without any visual redirection) all URLs from an existing folder (and everything inside of it) to its index.php file, similar as what Wordpress does, the problem is, no matter what I try it, either Wordpress overrides it showing their 404 Error page, or the site breaks.
For example, rewrite all of this URLs:
https://www.example.com/folder
https://www.example.com/folder/
https://www.example.com/folder/text
https://www.example.com/folder/text/
https://www.example.com/folder/some/text
https://www.example.com/folder/some/text/
https://www.example.com/folder/some/more/text/......
Basically anything inside /folder/ or any subfolder (whether exist or not) should be internally rewrite to https://www.example.com/folder/index.php and keeping the actual Wordpress working as usual.
I've tried some examples from other sites, as well as from similar questions like:
How does RewriteBase work in .htaccess
Redirect all to index.php using htaccess
.htaccess mod_rewrite - how to exclude directory from rewrite rule
The last one, is because I thought I could exclude the whole /folder/ path from Wordpress rewrites and create an .htaccess file inside that folder to manage it that way, well, Wordpress still shows its 404 error page.
Note: "folder" is a real folder inside the root domain, so is the main .htaccess file, and the Wordpress itself. This folder contains an index.php file.
This is the original Wordpress .htaccess file as shown here:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
I hope someone can help me out, thank you.
Related
My folders in my www directory as set up as follows:
www/forums
www/helpdesk
www/www
In the base www folder (not www/www), I have the following set up in my htaccess file to redirect based on subdirectory
# Direct subdomains to appropriate folder in WWW directory
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
I also have the following set up for configuring the index.php on the main site (www.example.com) - this is also in the htaccess file in the www directory:
# Rewrite rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ www/$1 [L,QSA]
The problem I am facing is that I have stuff from forums.example.com that I want to embed in www.example.com (Vanilla Forums + WordPress plugin) - if I configure this using the admin panels, the iFrame gets blocked because they are different domains.
I found out that when I go to www.example.com/forums, I get the same front page as forums.examples.com - but all the clean URLs break.
When I look at the .htaccess file in the www/forums folder, I see the following configuration
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L]
What do I need to do to the .htaccess file in the www directory so that when I go to www.example.com/forums, it works the same as if I went to forums.example.com
...the following set up in my htaccess file to redirect based on subdirectory
# Direct subdomains to appropriate folder in WWW directory
Aside: That snippet is just a canonical non-www to www redirect. It doesn't "redirect based on subdirectory" nor does it "direct [any] subdomains". (?)
the iFrame gets blocked because they are different domains.
It sounds as if you need to set an Access-Control-Allow-Origin HTTP response header on forums.example.com to allow the content to be "embedded" in example.com? Something like the following (using mod_headers) in the www/forums/.htaccess file:
Header set Access-Control-Allow-Origin "http://example.com"
What do I need to do to the .htaccess file in the www directory so that when I go to www.example.com/forums, it works the same as if I went to forums.example.com.
How do "all the clean URLs break"? However, given the HTTP header mentioned above, you shouldn't have to do anything more and still access forums.example.com (not the subdirectory).
Incidentally, the fact you can access the subdirectory (that the subdomain points to) is just how your hosting is configured. Normally you should block access to the subdirectory in order to prevent duplicate content issues (and any other issues, such as the linking problem you mention).
Also note, that due to the way mod_rewrite directives are inherited (or not in this case). The mod_rewrite directives in the www/forums/.htaccess file completely override the mod_rewrite directives in the parent folder.
I have installed wordpress to my public_html/ folder on my host. Now, I want to help my friend to get his own wp blog. I wanted to add a folder public_html/zoran/ where I wanted to install another wp and to add subdomain zoran.example.com to call that folder.
Problem is that .htaccess from public_html/ (my wp installation) is messing .htaccess inside public_html/zoran/ folder. I googled a lot, and figured out that this is impossible to have one .htaccess rules in root folder and other in subfolder (mod rewrite).
I cannot access my cPanel for couple of days now, and it will be unavailable for a few days, I recieved mail about that.
Now, I am at this point. I have moved my wp into public_html/www/ and I stored .htaccess file into public_html/ with following content:
# Rewriting conditions
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule (.*) http://www.example.com/ [R,L]
# Identify subdomain as %1
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
# Check if %1 is directory
RewriteCond %1 !-d
# rewrite the request to the subdomain's subfolder
RewriteRule (.*) %1/$1 [L]
Above code redirects example.com to www.example.com, and also, it opens my wp, stored in public_html/www/. But, when I try to go to zoran.example.com, I get 500 error, and that folder has just index.html file in it.
What is happening? How come that www folder works, and folder zoran does not work on same principle?!
I'm hoping someone might be able to help with a problem I'm having due to my lack of experience and knowledge with htaccess.
What we're doing is running IP Boards forum software and wordpress both in the root directory. The IPB has the index.php file (because of having indexed url's) and the new Wordpress's index.php file has been renamed to blog.php.
At the very top of the htaccess file we've added: DirectoryIndex blog.php index.php - so the new wordpress opens first.
The problem I'm having is trying to have 2 rewriterules in the htaccess file for the friendly urls from the forum software and also the permalinks for the new wordpress.
I can only seem to have one or the other.
Please could anyone tell me, or point me in the right direction to get both working.
This is what I'm doing so far but sadly no joy, but works fine if we remove one of the condition and rewrites.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog.php [L]
</IfModule>
Many thanks in advance.
Not sure if you still want an answer. Either way, if you are trying to go to two different pages you need some way of distinguishing them.
DirectoryIndex basically tells the default file (and order) when entering a directory. So http://host.com/ with both blog.php and index.php in the directory will serve up blog.php because it is first in the list you gave the server. If there is only index.php, it will serve that. If neither (and you don't have anything else in the list) it will throw a 404 because no default file is found.
EDIT: it will try to list contents if not found. My bad. If you don't allow directory listing, then it will probably show an error code. To turn off directory listing look in options: http://httpd.apache.org/docs/current/mod/core.html#options
http://httpd.apache.org/docs/current/mod/mod_dir.html
Your rewrite rules seem to kind of want do the same thing in a different order. If you request http://host.com/a and a is not a file or directory (according to the conditions) it will go to index.php.. if index.php doesn't exist, then it will loop until the server catches it, because you don't check that. So, that means the second set of conditions don't do anything, because either index.php exists or it doesn't and the next set probably won't really be reached unless it does.
You need to decide how to differentiate the two (/blog/ for the blog.php and / for index.php or something) and make one of them the default. If you want to randomize it, I would suggest doing that through PHP.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
.. to redirect from root to /forums/ through htaccess try this:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/forums/
RewriteRule ^(.*)$ /forums/$1 [L]
I have an htaccess file that I want to redirect the all pages to the another folder. I am using cakephp for the site, except for this folder which I want to redirect.
"/app/webroot/" is added to the new directory so the url is /app/webroot/new/ instead of just new.
I am placing this htaccess file (below) in the "new" directory and want anything at /app/webroot/new/ to redirect to /new/ and remove the /app/webroot/ This folder is independent of cakephp and thus does not need to be processed by cake.
The code below loops and I am not sure why.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /new/
# If your concerned about direct access to a particular page without the sub-dir
# you will want to add something like this
RewriteCond %{REQUEST_URI} !^/new
RewriteRule (.*) /new/$1 [R=301,L,NC]
You should NOT place the .htaccess file in /new/ but in /app/webroot/new/.
I am using codeigniter and when I set up the website I added necessary code in my .htaccess file to remove index.php (default) from my urls. I just happened to replace my public_html folder from a back up file of my website. Since I did that, I cannot get any of the links on home page to work unless insert index.php in the url between the domain name and the rest of the url as in http://www.obsia.com/index.php/contact/ instead of http://www.obsia.com/contact/ and it works. So, in my config file within the application folder, I changed
$config['index_page'] = "";
to
$config['index_page'] = "index.php";
and all the links seem to work now. But how do I remove index.php from the URLs.
Here is what my .htaccess code looks like:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt|css)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Can anyone point me in the right direction. It will much appreciated.
Regards,
G
What yo want to do can be done this way:
RewriteEngine on
RewriteBase /
# Static content. Rewrite to - (don't change) and mark as last rule.
RewriteRule !^(index\.php|public|user_guide|robots\.txt|css) - [L]
# Do the rewrite.
RewriteRule ^(.*)$ /index.php?/$1 [L]
However, a slightly better way of doing that is this:
RewriteEngine on
RewriteBase /
# Only do the rewrite under the condition that the requested URL isn't a (real) file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/$1 [L]
there are so many ht access files... In my case i was editing the wrong file... u should edit the file that is inside the project.. for example i work on code igniter and project name was test , so inside test folder i had a htaccess file and inside my application folder ie test/application there was another htaccess file.. i was editing the access file inside the application folder, but i had to edit the file in test folder not test/application/.htaccess.... hope sum 1 finds this useful.. cos i spent half a day to figure this out :(
Cheers
ksp