I'm writing web application using codeigniter framework. Here is the structure of document root
application
system
website
What I want is that only the website directory to be accessаble. Here is the content of .htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/website/
RewriteRule .* /website/%1 [QSA]
When I type the site url in browser I'm redirected to website dir. So far, so good. It works.
The problem comes when I try to access a dir within the website directory. I get
404 page not found
What to do so the directories below the website dir to be accessаble ?
This is the rule you need:
RewriteRule (?!^website(/.*|)$)^.*$ website%{REQUEST_URI} [L,NC]
Try
RewriteEngine on
RewriteBase /
RewriteCond $1 !^website
RewriteRule ^(.*)$ website/$1 [L]
Related
I'm in the process of transitioning my single site WordPress installation into a multi-site. I'm trying to fix the broken CSS/JS from my main site.
I currently have two sites on my network:
http://www.example.com (primary)
http://dev.example.com (secondary)
My multi-site installation is inside of a subdirectory we will call "wordpress". So the file path looks like public_html/wordpress.
My goal is for neither site to have the "wordpress" subdirectory in the URL. Everything seems to be working except for broken CSS and JS on the primary site (the secondary site looks fine).
When inspecting the code, all of the CSS and JS calls point to http://www.example.com/wp-content/ but the files are not found there. The files will be found if I go to http://www.example.com/wordpress/wp-content in my browser. I want to hide the wordpress folder and still be able to retrieve the files.
I'm confused on how to setup the HTACCESS file. I already made some initial changes to it in order to get the multi-site within the subdirectory working. These were all following guides I found on StackOverflow and elsewhere online in regard to how to move your site into a multi-site with subdirectory and hiding the subdirectory. I haven't found anything about addressing the broken CSS/JS issue.
I figured I need to make updates to one or more of 3 HTACCESS files.
1.) public_html/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ /wordpress/index.php [L]
</IfModule>
2.) public_html/wordpress/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
3.) public_html/wordpress/wp-content/.htaccess
This file didn't exist but I created it. My thinking was that files are being called without the wordpress subdirectory but they need to act like they have the subdirectory included in them. For example, currently http://www.example.com/wp-content/uploads/image.jpg is broken but http://www.example.com/wordpress/wp-content/uploads/image.jpg works. I want it to be the other way around or I want both paths to work.
<IfModule mod_rewrite.c>
RewriteEngine on
# ADD WORDPRESS IF URL DOES NOT HAVE IT
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteRule ^(.*)$ /wordpress/$1
</IfModule>
I've tried adding different lines to the various HTACCESS files but none of them worked. I also not sure what line number I should insert a new rule. It's possible that one of my new rules is correct but it is in the wrong place. Below is one that I really thought would work but didn't.
RewriteRule ^/wp-content/(.*)$ /wordpress/wp-content/$1 [R=301,NC,L]
First, you should remove all the .htaccess files and keep only the one in the root: public_html/.htaccess
Second, your last rule isn't working because is slightly wrong.
You should change it from:
RewriteRule ^/wp-content/(.*)$ /wordpress/wp-content/$1 [R=301,NC,L]
To:
RewriteRule ^wp-content/(.*)$ wordpress/wp-content/$1 [L,NC]
Because you don't need the starting / and you don't need to 301 redirect. You want to keep your wordpress folder hidden and just map the requested URLs from wp-content/(.*) to wordpress/wp-content/$1
Also, this rule must be the first in your .htaccess file to have priority over following default Wordpress rules. Your final and only .htaccess from public_html/ should look like this:
RewriteEngine On
RewriteBase /
RewriteRule ^wp-content/(.*)$ wordpress/wp-content/$1 [L,nc]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I hope it helps you.
You shouldn't have to set up several .htaccess files in your sub-directories.
The only .htaccess file that need to be modified is the one located in the application root directory. In your case, it seems to be your public_html/.htaccess or your public_html/wordpress.
Now by default WordPress generates an .htaccess file in that directory which looks something like the following:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
In order to rewrite your URLs, you need to add your RewriteRules before the WordPress code block.
Since RewriteRules are processed from top to bottom, if the request is first rewritten to index.php by the WordPress block, then your rule will never be processed.
Therefore your RewriteRule:
RewriteRule ^/wp-content/(.*)$ /wordpress/wp-content/$1 [R=301,NC,L]
should be enough if it's placed at the top of the root directory's .htaccess, and remove the .htaccess file in the sub-directories
Most Multisite networks are installed in the root directory of your site. This means that if your server is using example.com, then this will be the URL for your base site on the network.
If you’ve installed WordPress Multisite in a subdirectory, then you can’t use subdomains.
If you already have a single site installation at example.com, and you add another WordPress installation in a subdirectory running Multisite, then its address will be example.com/wordpress.
Any site you create on your new network will be at example.com/wordpress/my-new-site. Creating a subdirectory would be impossible here, as it would have to be at an address like example.com/wordpress/my-new-site.network Which just doesn’t work.
I have this in my html folder
--html
--.htaccess
--app
--application_name
--public
--index.php
--landing_page
--index.php
As of now, everytime the website url is accessed (www.website.com), the browser opens the landing_page/index.php.
How can I make it that when I access www.website.com/beta, I will be doing a request to html/app/application_name/public/index.php
I have tried adding this to the .htaccess
RewriteRule ^beta/?$ app/application_name/public/index.php [L,NC]
This is the whole .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^beta/?$ app/application_name/public/index.php [L,NC]
But it does not work. Not sure what term to use to search for this kind of problem.
Your root is currently set at /html, and therefore the RewriteBase / is at /, the /beta/ simply does not exist. You could change the RewriteBase /app/application_home/public/ and set the RewriteRule ^beta/?$ index.php [L,NC]. This however no longer give you the access to the landing page, not sure if this is what you want?
I have a folder structure like this
/first/second/{application}
And I would like that trough htaccess to load content from application without those two directories to appear. So www.domain.com would load www.domain.com/first/second and www.domain.com/something/anything would load www.domain.com/first/second/something/anything
I tried with RewriteRule ^(.*)$ /first/second/index.php/$1 [L] in htacces in root folder but without any success.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/first/second/
RewriteRule ^(.*)$ /first/second/$1
I have just uploaded all file of my test website to 000webhost.com domain.
My site is farazphptest.comxa.com
I was working on Codeigniter before uploading the site. All of my controllers are working fine on my localhost, but after uploading the site on server when i try to access a controller say farazphptest.comxa.com/welcome where "Welcome" is my webpage/controller, it does not work and opens "error404.000webhost.com/?" All of my controller including "welcome" are working fine on localhost, but after uploading website on domain only the home page loads perfectly.
This is the 1st time i have put a site on web, do tell me if i am missing out some tricks. I have just simply copied my file on web as stated. Thanks
Here is my .htaccess file used in both for localhost and on server.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /faraztest
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /faraztest/index.php
</IfModule>
An alternative solution is to create sub-domain on 000webhost.com with project name , and call the project from sub domain url Directly, it will be like this :
From Cpanel got to Subdomains
Create new subdomain with project folder name. ex : test.farazphptest.comxa.com
Overwrite the created subdomain folder with your project folder. ex : test
Edit your .htaccess in your main uploaded project folder to be like this :
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
now you can call your project directly from the new subdomain url.
ex : http://test.farazphptest.comxa.com
Following solved my problem
My .htccess file is
# index file can be index.php, home.php, default.php etc.
DirectoryIndex index.php
# Rewrite engine
RewriteEngine On
# condition with escaping special chars
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
and it worked like charm!
I tried to rewrite a simple RewriteRule but i guess it doesn't turn up good. I created a htaccess file in wordpress wp-admin folder and i tried to rename the wp-admin directory name in my localhost.Here is the code i tried
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^wp-admin$ hello
Just for testing i had done this in my localhost. I want to start from simple pattern not complex pattern so i tried other simple pattern wp-admin and replacement as hello
RewriteEngine On # Turn on the rewriting engine
RewriteRule wp-admin hello
When i go to http://localhost/my_site/hello i can't able to direct to wp-admin for this am getting 404 error. When i try http://localhost/my_site/wp-admin am getting internal server error.
I think the rewrite rule is not good in my try. I have one more doubt should place the .htaccess file in the wp-admin directory or in the my site root directory in my_site or should i place in every directory which am trying to change the folder name on the fly.
What wrong am i doing here.Any help please?
RewriteRule ^hello(.*)$ wp-admin$1 [QSA]
Will change:
http://yourdomain.com/yourwp/hello
http://yourdomain.com/yourwp/hello/path/in/admin
to
http://yourdomain.com/yourwp/wp-admin
http://yourdomain.com/yourwp/wp-admin/path/in/admin
The QSA flag is useful for compatibility.
Here is my wordpress .htaccess with only one custom redirect, but you can understand the idea:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^login/?$ /wp-login.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress