My front end is in angular. I am using HTML5 mode routing in angular. I have configured my htaccess file for redirecting any URL to index.php, But it seems that it is not working.
Below is my htaccess code :
Options +FollowSymLinks
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.php/#/$1 [L]
</ifModule>
Please help.
Change this line :
RewriteRule (.*) index.php/#/$1 [L]
By this :
RewriteRule ^(.*)$ /index.php?/#/$1 [L]
Related
The routing url is like 'my_website/:param'
But my location contain a folder name is as same as the params.
So when I browse with http://my_website/apple.
The browser will display the folder instead of pass the value 'apple' to the web.
How should I set the .htaccess?Thanks
The following only work when the folder with same value is not exist.
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]
</ifModule>
Based on your shown samples, could you please try following. Please clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.html [L]
OR if you are looking only for link which starts with apple then try following.
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^apple index.html [NC,L]
Problem in OP's tried code: RewriteRule ^(.*) index.html [NC,L] will create an loop because there is no condition mentioned, so its going true each time for each uri.
Using create-react-app together with react-router, how can I make any of the following variations (I don't think I missed any):
www.example.com
example.com
http://example.com
http://www.example.com
redirect to:
https://www.example.com (notice the https, secured)
I tried adding a subdomain of www, then created an .htaccess file with the following code:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
When I add that, react routes don't work, and I get a blank page. (I'm using 1and1 to host.)
What am I doing wrong, and how can I fix it?
I got this issue and i'm also using 1&1,
It this because you need to redirect everything to your index.html in order to make react-router work properly.
Here, you only making an http to https redirection, which is the first part on the job.But, you also need to make that https request redirect to your index.html file.
So you make your http to https redirection :
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R=301]
Then, if https is "on" you redirect everything to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ /index.html [NC,L,QSA]
And you can test your .htaccess here : https://htaccess.madewithlove.be/
It works fine in theory, but i don't know why in my case it the redirection didn't works when the URI was "/".
So I added this :
"If https is not activate and the URI is "/" then redirect to the root of my website with https"
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^.$
RewriteRule .* https://"your-site.com"/ [NC,L,R=301]
To summarize the answer
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^.$
RewriteRule ^(.*)$ https://"your-site.com"/ [NC,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ /index.html [NC,L,QSA]
</IfModule>
I would like to redirect the Facebook crawlers to a static page, since my website is in AngularJS and I need to work with the og:meta. I'm using Wordpress as back-end, so at the moement this is my .htaccess:
# 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 tryed to add these two lines:
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet)
RewriteRule tracks/(\d*)$ http://<path>/static.php [P]
But this is not working. If I try to scrape a page with the facebook tool (https://developers.facebook.com/tools/debug/) I'm not redirect to the static page.
Keep in mind that in wordpress my permalinks are build in this way: http://<fqdn>/%category%/%postname%/ and tracks/ is one of my category.
The solution was to exclude the facebook crawler from the default 302 of wordpress.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_USER_AGENT} !facebookexternalhit/1.1
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} facebookexternalhit/1.1
RewriteRule (.*) http://<dn>/static.php [L]
</IfModule>
i have a angular project with routes in html5 mode. I set up a htaccess file, that is possible to insert a domain manually or refresh the page.
here the htaccess code with works fine, based on this
Still getting 'Not Found' when manually refreshing with angular.js route
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ myFolder/myFile.php [L]
but now i want also to redirect the url to https width www, for example:
http://example.com should become https://www.example.com
there for i used this:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
But when i try to combine this scripts i always get error!
Thanks!
I'm not sure how you're trying to combine the code, but you should be able to do it this way. Replace example.com with your domain.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ myFolder/myFile.php [L]
Clear your browser cache before trying the new rules.
I have problems with my rewrite rules, I want that http://example.com/b/abc calls banner.php?b=abc, that works. But when I type http://example.com/index.php?mode=mybanners it will call banner.php?b=index.php?mode=mybanners (or something like this). My .htacces file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule b/?(.+)$ ./banner.php?b=$1
RewriteRule i/?(.+)$ ./banner.php?bi=$1
</IfModule>
Some ideas to let /index.php interact normal?
Try below rules :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule b/?(.+)$ ./banner.php?b=$1
</IfModule>