I am using this htaccess for my application.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any URL I will type in my browser, if the respective file doesn't exist, it will open the index.php.
The problem is I have many applications like this installed on the same domain.
For example, the root contains an index.php file and a htaccess like above.
I have also, /store, which contains a index.php file and a htaccess like above, too, but when I access /store/something it opens the index.php of root (not the correct /store/index.php
How can I solve this problem (how to make the htaccess of root to not override the htaccess of /store)? Thanks!
You can have a skip directory rule to skip all the directories:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# skip index.php and some directories
RewriteRule ^(store/|site1/|site2/|index\.php$) - [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Related
I have a small mvc application where I'm trying to force the url to go from www.example.com to www.example.com/public.
In order to do this, I have a .htaccess file in the root (/) and then another .htaccess within the /public folder to point to index.php with friendly urls. I believe the issue is within the htaccess file that sits in the public folder, I need all requests to go through index.php
I have tried a few threads on stackoverflow but seems to give me a server 500 error when I access www.example.com
.htaccess of root
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /public/
</IfModule>
.htaccess of public folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}% !-f
RewriteCond %{REQUEST_FILENAME}% !-d
#allow images, css and js links
RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule (.*) /public/index.php
I have a WordPress site hosted on AWS and I am having a hard time to configure mod_rewrite to work correctly.
Folder structure
/root
|_ staging/
|_ live/
The .htaccess is the WordPress default
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Main Problem
I can access /staging/index.php/api which I used to access it without subdirectories like this ---.com/api.
When I try /staging/api it shows File not found.
I tried to change the .htaccess to different thing but none of them was successful.
There are no .htaccess file in the root directory.
Some help would be appreciated =)
Thanks in advance.
Try this code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /staging
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /staging/index.php [L]
</IfModule>
Note: The AllowOverride should be set to All in server configuration.
You can find the reference from here.
How to Set AllowOverride all
I'm basically trying to have everything that's not a file (.css, .js, .jpg, etc...) rewrite to index.php to create sym-links. The code I have in my .htaccess file works for my root directory and for a single subdirectory So. "localhost/" and "localhost/help" both work, but "localhost/help/article-27" does not work. The .htaccess seems to rewrite everything when I try to use that second sub-directory, including JS and CSS files. Does anyone know why that is? Here's my code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
As darren mentioned as per the comments it's not required to have $1 !!.(gif|jpe?g|png)$ [NC]
This will work for all the levels and CSS files whether symlink / direct links.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
Here is my folder structure
www.mywebsite.com
www.mywebsite.com/app
www.mywebsite.com/app/firstproject
www.mywebsite.com/app/secondtproject
In the root directory i installed wordpress. It allows me to access the www.mywebsite.com/app but when i try to access the www.mywebsite.com/app it is always showing page not found i can guess that it is because of the .htaccess at the root folder.
Here is the .htaccess root folder
# 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
I tried to override the .htaccess to the sub folders by having the below code in the .htaccess of the app folder but it shows the same page not found error.
RewriteRule ^app/ - [L]
How can i access the www.mywebsite.com/app/firstproject without that error ?
Remove app/.htaccess
Have this code in root .htaccess:
root .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(index\.php$|app/) - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress
Write all rules in the root htaccess file.
add
RewriteRule ^app/firstproject$ - [L]
to prevent rewrite in this path.
For further rewrite within /firstproject, you need conditions and rules similar to web root
RewriteEngine On
RewriteBase /
RewriteRule ^app/firstproject$ - [L] #add longer path first
RewriteRule ^index.php$ - [L] #no need to escape \.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I got the following .htaccess for my apache2 webserver in e. g. "some-folder":
<IfModule mod_rewrite.c>
RewriteEngine On
# Folders / files to exclude from rewrite divided by Pipe goes here:
RewriteRule (^|/)web(/|$) - [L,NC]
# turn empty requests into requests for "index.php",
# keeping the query string intact
RewriteRule ^$ index.php [QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !favicon.ico$
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
for http://host/some-folder/index/index it works, but for http://host/some-folder/ajax/test it doesn´t. It should redirect both to index.php.
What went wrong?
Edit: If I set the RewriteBase to
RewriteBase /~alpham8/ephp/
it works.
So, the folder under which the .htaccess file is located (in my case a home_dir). But how can I do the same without knowing the current directory under which the .htaccess file is located?