Wordpress Apache RewriteRule - angularjs

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>

Related

Site home page not redirecting to prerender.io

Have a site built with Angular 1.5 that is using prerender.io to server pages to bots. For the most part it is working well, however, The home page of the site does not appear to be redirecting to prerender which is causing me some issues. The path to my index file for angular is /templates/index.html.
<IfModule mod_headers.c>
RequestHeader set X-Prerender-Token "xxxxxxxxxxxxxxxx"
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
<IfModule mod_proxy_http.c>
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|rogerbot|linkedinbot|embedly|quora\ link\ preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator [NC,OR]
RewriteCond %{QUERY_STRING} _escaped_fragment_
RewriteRule ^(?!.*?(\.js|\.css|\.xml|\.less|\.png|\.jpg|\.jpeg|\.gif|\.pdf|\.doc|\.txt|\.ico|\.rss|\.zip|\.mp3|\.rar|\.exe|\.wmv|\.doc|\.avi|\.ppt|\.mpg|\.mpeg|\.tif|\.wav|\.mov|\.psd|\.ai|\.xls|\.mp4|\.m4a|\.swf|\.dat|\.dmg|\.iso|\.flv|\.torrent|\.ttf|\.woff|\.svg|\.eot|\.woff2))(.*) http://service.prerender.io/https://www.example.com/$2 [P,L]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.+)\.xml$ http://content.example.com/$1.xml [P]
</IfModule>
RewriteRule ^(.*) templates/index.html [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/])$ /$1$2/ [L,R=301]
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "GET,POST,PUT,OPTIONS"
Header set Access-Control-Allow-Credentials "true"
Not great with htaccess or httpd.conf. Took over this from another developer. Any insite would be a great help.

having issues with htaccess in codeigniter Angularjs

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]

My cakephp 2.2 site not working on subdomain

My cakephp 2x site working fine on my local machine.
But i have upload on sub domain server it is not working.
I want my cakephp site working on sub domain with admin Prefix
http://vertaxtechnology.com/ => is my domain
http://dev.vertaxtechnology.com/ = is my sub domain
http://dev.vertaxtechnology.com/eventapp = is my cake directory
This is my Root htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /eventapp/
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This is my app htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /eventapp/
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This is my webroot htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Please help thanks

apache don't rewrite index.php and others

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>

Installing/Setting cakePHP on Server

I'm trying to setup my cakephp work on server
Purchased godaddy shared server
when i go to my site http://xyz.com/cake/
I'm getting 404 error
The requested URL /xyz/cake/app/webroot/ was not found on this server.
anyhelp plz ??
Thanks,
Satish
You need to set the correct RewriteBase in your .htaccess if you're going to run Cake inside a subdirectory.
Both /xyz/cake/.htaccess and /xyz/cake/webroot/.htaccess (assuming /xyz/cake is the path to Cake and your app dir) need to be updated.
/xyz/cake/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /xyz/cake/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/xyz/cake/webroot/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /xyz/cake/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Resources