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]
Related
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]
I have 3 folders in a sub directory of my root directory i would like to combine.
My site map:
mywebsite.com
mywebsite.com/test/
mywebsite.com/test/one/
mywebsite.com/test/one/one.php
mywebsite.com/test/two/two.php
mywebsite.com/test/three/three.php
I would like to access:
mywebsite.com/test/one/one.php
mywebsite.com/test/two/two.php
mywebsite.com/test/three/three.php
by using:
mywebsite.com/test/combine/one.php
mywebsite.com/test/combine/two.php
mywebsite.com/test/combine/three.php
Solution...
RewriteEngine On
RewriteRule .* - [E=directory:/test/]
RewriteRule .* - [E=one:one/]
RewriteRule .* - [E=two:two/]
RewriteRule .* - [E=three:three/]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:one}$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:one}$1 -d
RewriteRule ^combine/(.*)$ %{ENV:directory}%{ENV:one}$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:two}$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:two}$1 -d
RewriteRule ^combine/(.*)$ %{ENV:directory}%{ENV:two}$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:three}$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:directory}%{ENV:three}$1 -d
RewriteRule ^combine/(.*)$ %{ENV:directory}%{ENV:three}$1 [L]
This works but i would like to minimize the script
Try it this way for consolidation, if you simplify it.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/test/$1/$1.php -f
RewriteRule ^combine/(.*)(?:\.php)$ /test/$1/$1.php [L]
I want to redirect all url from http to https, this works just fine for me.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Now i want to add one exception to this rule, i.e whenever a user request the following dynamic url (the last string is dynamically generated) it should not apply force https redirect.
sub.domian.dev/api/v/1/download/zip/token/8397298347ksjdnkjasdn0394834
I tried this rule which does not work.
#url to exclude
RewriteCond %{REQUEST_URI} !^/api/v/1$
Can someone give me the pointer on how to go with this?
Thanks.
You can use this code:
RewriteEngine On
# except /api/v/1/ requests redirect everything else to https
RewriteCond %{THE_REQUEST} !\s/+api/v/1/ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.php [L]
You can use:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/api/v/1/
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I have a couple pages:
http://waleyqiao.com/about/
http://waleyqiao.com/index/
http://waleyqiao.com/contact/
http://waleyqiao.com/blog/
http://waleyqiao.com/portfolio/
The real pages would be waleyqiao.com/about.html
htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
For some reason, waleyqiao.com/portfolio/ does not seem to work but waleyqiao.com/portfolio.html does...
It's because you are tacking the .html right on the end of the URI:
/portfolio/.html
which obviously doesn't exist. You need to create a grouping without the trailing slash. Try this instead:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1\.html -f
RewriteRule ^ /%1.html
And likewise for the php extension:
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1\.php -f
RewriteRule (.*) /%1.php [L]
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]