htaccess - do not rewrite in this case - .htaccess

My access file looks like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
But I have a directory called facebook that I want to access as usuall through the URL http://mysite.com/facebook. What do I need to add to the above so that it ignores (does not rewrite) this directory?

add:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI} !^/facebook
RewriteRule ^.*$ index.php [NC,L]

Related

htaccess two endpoints showing same

I have two endpoints on my website /i/ snd /a/. They do show different information, but both the same. Currently, I have the /i/ working like so..
/i/12345 (where 12345 is the itemId).
/a/67890 (where 67890 is the itemId that is active).
If I goto /a/67890, itll show the /i/ UI, not the /a/ UI. Here is my .htaaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?hostname\.app
RewriteRule ^(.*)$ https://www.hostname.app/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /i/index.php?id=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /results/index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /a/index.php?id=$1 [NC,L]
What am I doing wrong? It looks like /a/ is being routed to /i/.
Have it this way:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?hostname\.app$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([ia])/(.*)$ $1/index.php?id=$2 [NC,QSA,L]
RewriteRule ^(results)/(.*)$ $1/index.php?/$2 [L,QSA]

htaccess remove param key not working as intended

I currently have in place a rewrite rule to remove a key on one of the sites.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /i/index.php?id=$1 [NC,L]
I now want to add this rule.
RewriteRule ^(.*)$ /stash/index.php?sid=$1 [NC,L]
However, this does not work.
HOST_NAME/stash/123 will not work.
HOST_NAME/stash?sid=123 will.
The PHP is simple....
echo $_GET['sid'];
Here is my full HTACCESS
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?hostname\.com
RewriteRule ^(.*)$ https://www.hostname.com/$1 [R,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /i/index.php?id=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ /stash/index.php?sid=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /results/index.php?/$1 [L]
Any help on this would be great.
UPDATE
There are four main directories on the website.
/results
/i
/stash
/account
I dont care if /results shows ?id=1$store=1...etc
I dont want /i and /stash to show that. I would want those to look like...
/i/123456789 instead of /i?id=123456789
/stash/hgdG54Hj9 instead of /stash?sid=hgdG54Hj9
Looks like you have nice directory based URI structures. In that case you can just have a per directory .htaccess
You may use this code in your root .htaccess:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(?:www\.)?(hostname\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
Inside stash/.htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]
And similarly inside i/.htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]

Replace a part of url with htaccess RewriteRule

I have a part of url to replace with htaccess :
How to replace root/aaa/bbb/css/images/ddd.image.png to root/aaa/css/images/ddd.image.png
I tried without success this code in the .htaccess in the root folder :
RewriteEngine On
RewriteRule ^aaa/bbb/(.*) /aaa/$1 [L,QSA,R=301]
In the aaa folder, there is this .htaccess :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
You need to use this rule in /aaa/.htaccess:
RewriteEngine On
RewriteBase /aaa/
RewriteRule ^bbb/(.+)$ $1 [L,NC,R=301,NE]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.php [L]

htaccess rules to skip files and directory but checking by matching with a prefix first

I am using following rules which skips files if paths to them is already provided.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^$ public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.+)$ public/index.php?r=$1 [L,QSA]
But this makes me, to access the files like site.com/public/js/somefile.js, which is not intented.
Can we check if file exists inside a directory and rewrite the url so to access it as `site.com/js/somfile.js"
RewriteCond %{REQUEST_FILENAME} -"public/"f
RewriteRule ^ - [L]
Obvioulsy this didn't work. Any ideas?
Right before this rule:
RewriteRule ^$ public/index.php [NC,L]
Add this rule:
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -d
RewriteRule ^(.+)$ /public/$1 [L]

Add another exception to htaccess?

My .htaccess file alows access to real files & folders on the server. For anything else, it will redirect to /index.php, except when the app folder is specified in which case it will redirect to /app/index.php. I want to add a second folder named appbeta which will redirect to /appbeta/index.php. How should I modify my .htaccess to add this additional exception?
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!app)(.+)$ /index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app(.+)$ /app/index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I am not exactly sure what the following rewrite does:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!app)(.+)$ /index.php?u=$1 [NC,QSA,L]
However, if your current .htaccess is working as you want, I would try the following which puts a rewrite for /appbeta right before the rewrite for /app:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!app)(.+)$ /index.php?u=$1 [NC,QSA,L]
# rewrite /addbeta to /appbeta/index.php ...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^appbeta(.*)$ /appbeta/index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^app(.+)$ /app/index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
note: no new question started as mentioned in comments, fix above (change ^appbeta(.+)$ to ^appbeta(.*)$)

Resources